#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
檢查匯入問題
"""

import pandas as pd
import sys

# 可能的路徑
possible_paths = [
    '/Users/ogt/momo_pro_system/缺貨測試.xlsx',
    '/Users/ogt/缺貨測試.xlsx',
    '/Users/ogt/Downloads/缺貨測試.xlsx',
]

excel_path = None
for path in possible_paths:
    try:
        df = pd.read_excel(path)
        excel_path = path
        break
    except:
        continue

if not excel_path:
    print("找不到 Excel 檔案")
    sys.exit(1)

print("=" * 80)
print(f"Excel 路徑: {excel_path}")
print("=" * 80)

# 讀取 Excel
df = pd.read_excel(excel_path)

print(f"\n總行數: {len(df)}")
print(f"總欄位數: {len(df.columns)}")

print(f"\n所有欄位名稱（共 {len(df.columns)} 個）：")
for i, col in enumerate(df.columns, 1):
    print(f"   {i:2d}. '{col}'")

print(f"\n第一行數據：")
print("-" * 80)
for col in df.columns:
    value = df[col].iloc[0]
    value_type = type(value).__name__
    print(f"   {col}: {value} (類型: {value_type})")

# 檢查關鍵欄位
print(f"\n檢查關鍵欄位：")
print("-" * 80)
key_fields = ['區ID', '區名稱', '借採轉', '缺貨日期', '缺貨天數', '商品可賣量', '庫存水位']
for field in key_fields:
    if field in df.columns:
        value = df[field].iloc[0]
        print(f"   ✅ {field}: {value} (類型: {type(value).__name__})")
    else:
        print(f"   ❌ {field}: 欄位不存在")
