"""
檢查租戶初始化狀態
"""
import psycopg2

conn = psycopg2.connect(
    host="10.1.0.20",
    port=5433,
    database="hr_portal",
    user="admin",
    password="DC1qaz2wsx"
)
cur = conn.cursor()

# 查詢租戶狀態
cur.execute("""
    SELECT id, code, name, is_initialized, initialized_at, initialized_by, status
    FROM tenants
    ORDER BY id;
""")

tenants = cur.fetchall()

print("=== Tenants Status ===\n")

for t in tenants:
    print(f"ID: {t[0]}")
    print(f"Code: {t[1]}")
    print(f"Name: {t[2]}")
    print(f"Is Initialized: {t[3]}")
    print(f"Initialized At: {t[4]}")
    print(f"Initialized By: {t[5]}")
    print(f"Status: {t[6]}")
    print("-" * 50)

# 查詢系統狀態
cur.execute("""
    SELECT current_phase, initialization_completed, is_locked
    FROM installation_system_status
    WHERE id = 1;
""")

sys_status = cur.fetchone()
if sys_status:
    print("\n=== System Status ===\n")
    print(f"Current Phase: {sys_status[0]}")
    print(f"Initialization Completed: {sys_status[1]}")
    print(f"Is Locked: {sys_status[2]}")

cur.close()
conn.close()
