"""
FreeFlow 기본 경비 카테고리 시드 데이터
시스템 기본 카테고리를 생성합니다 (user_id=0 으로 시스템 카테고리)
"""
import mysql.connector

DB_CONFIG = {
    'host': 'officialsite.kr',
    'port': 23306,
    'user': 'admin',
    'password': 'dlgks~123',
    'database': 'freeflow',
}

CATEGORIES = [
    {'slug': 'saas', 'name_ko': 'SaaS 구독', 'name_en': 'SaaS Subscription'},
    {'slug': 'outsourcing', 'name_ko': '외주비', 'name_en': 'Outsourcing'},
    {'slug': 'infrastructure', 'name_ko': '인프라', 'name_en': 'Infrastructure'},
    {'slug': 'marketing', 'name_ko': '마케팅', 'name_en': 'Marketing'},
    {'slug': 'office', 'name_ko': '사무용품', 'name_en': 'Office Supplies'},
    {'slug': 'entertainment', 'name_ko': '접대비', 'name_en': 'Entertainment'},
    {'slug': 'education', 'name_ko': '교육비', 'name_en': 'Education'},
    {'slug': 'software', 'name_ko': '소프트웨어', 'name_en': 'Software'},
    {'slug': 'transport', 'name_ko': '교통비', 'name_en': 'Transportation'},
]

def seed_for_user(cursor, user_id):
    """특정 사용자에 대해 기본 카테고리를 생성"""
    for cat in CATEGORIES:
        cursor.execute("""
            INSERT IGNORE INTO expense_categories (user_id, name_ko, name_en, slug, is_system, created_at)
            VALUES (%s, %s, %s, %s, 1, NOW())
        """, (user_id, cat['name_ko'], cat['name_en'], cat['slug']))
    return len(CATEGORIES)

def main():
    conn = mysql.connector.connect(**DB_CONFIG)
    cursor = conn.cursor()

    # 모든 기존 사용자에게 기본 카테고리 생성
    cursor.execute("SELECT id FROM users")
    users = cursor.fetchall()

    if not users:
        print("⚠️  No users found. Categories will be created when users sign up.")
    else:
        for (user_id,) in users:
            count = seed_for_user(cursor, user_id)
            print(f"✅ Seeded {count} categories for user {user_id}")

    conn.commit()
    cursor.close()
    conn.close()

if __name__ == '__main__':
    main()
