"""
FreeFlow 구독 플랜 및 부가서비스 시드 데이터
"""
import mysql.connector
import json

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

PLANS = [
    {
        'plan_id': 'free',
        'name': 'Free',
        'name_ko': '무료',
        'price': 0,
        'credit_bonus': 0,
        'total_credits': 100,
        'features': json.dumps(['Basic document creation', 'Up to 3 clients', 'Basic reports']),
        'features_en': json.dumps(['Basic document creation', 'Up to 3 clients', 'Basic reports']),
    },
    {
        'plan_id': 'starter',
        'name': 'Starter',
        'name_ko': '스타터',
        'price': 29000,
        'credit_bonus': 500,
        'total_credits': 500,
        'features': json.dumps(['Unlimited documents', 'Up to 10 clients', 'Standard reports', 'Email support']),
        'features_en': json.dumps(['Unlimited documents', 'Up to 10 clients', 'Standard reports', 'Email support']),
    },
    {
        'plan_id': 'basic',
        'name': 'Basic',
        'name_ko': '베이직',
        'price': 59000,
        'credit_bonus': 1500,
        'total_credits': 1500,
        'features': json.dumps(['Everything in Starter', 'Unlimited clients', 'Advanced reports', 'Template customization', 'Priority support']),
        'features_en': json.dumps(['Everything in Starter', 'Unlimited clients', 'Advanced reports', 'Template customization', 'Priority support']),
    },
    {
        'plan_id': 'pro',
        'name': 'Pro',
        'name_ko': '프로',
        'price': 99000,
        'credit_bonus': 5000,
        'total_credits': 5000,
        'features': json.dumps(['Everything in Basic', 'AI consultation', 'Auto bank/card sync', 'HomeTax integration', 'Dedicated support']),
        'features_en': json.dumps(['Everything in Basic', 'AI consultation', 'Auto bank/card sync', 'HomeTax integration', 'Dedicated support']),
    },
]

ADDONS = [
    {
        'addon_id': 'tax-invoice-lookup',
        'name': 'Tax Invoice Lookup',
        'name_ko': '세금계산서 조회',
        'price': 9000,
        'unit': 'month',
        'unit_ko': '월',
        'description': 'Look up and verify tax invoices from NTS',
        'description_ko': '국세청 세금계산서 조회 및 검증',
        'per_unit': False,
    },
    {
        'addon_id': 'cash-receipt-lookup',
        'name': 'Cash Receipt Lookup',
        'name_ko': '현금영수증 조회',
        'price': 5000,
        'unit': 'month',
        'unit_ko': '월',
        'description': 'Look up and verify cash receipts from NTS',
        'description_ko': '국세청 현금영수증 조회 및 검증',
        'per_unit': False,
    },
    {
        'addon_id': 'card-sync',
        'name': 'Card Sync Slot',
        'name_ko': '카드 연동 슬롯',
        'price': 5000,
        'unit': 'slot/month',
        'unit_ko': '슬롯/월',
        'description': 'Automatically import credit card transactions',
        'description_ko': '신용카드 거래 자동 가져오기',
        'per_unit': True,
    },
    {
        'addon_id': 'bank-sync',
        'name': 'Bank Sync Slot',
        'name_ko': '은행 연동 슬롯',
        'price': 8000,
        'unit': 'slot/month',
        'unit_ko': '슬롯/월',
        'description': 'Automatically import bank transactions',
        'description_ko': '은행 거래 자동 가져오기',
        'per_unit': True,
    },
]

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

    # Seed plans
    for plan in PLANS:
        cursor.execute("""
            INSERT INTO plans (plan_id, name, name_ko, price, credit_bonus, total_credits, features, features_en, is_active, created_at)
            VALUES (%(plan_id)s, %(name)s, %(name_ko)s, %(price)s, %(credit_bonus)s, %(total_credits)s, %(features)s, %(features_en)s, 1, NOW())
            ON DUPLICATE KEY UPDATE
                name=VALUES(name), name_ko=VALUES(name_ko), price=VALUES(price),
                credit_bonus=VALUES(credit_bonus), total_credits=VALUES(total_credits),
                features=VALUES(features), features_en=VALUES(features_en)
        """, plan)
    print(f"✅ Seeded {len(PLANS)} plans")

    # Seed addons
    for addon in ADDONS:
        cursor.execute("""
            INSERT INTO addons (addon_id, name, name_ko, price, unit, unit_ko, description, description_ko, per_unit, is_active, created_at)
            VALUES (%(addon_id)s, %(name)s, %(name_ko)s, %(price)s, %(unit)s, %(unit_ko)s, %(description)s, %(description_ko)s, %(per_unit)s, 1, NOW())
            ON DUPLICATE KEY UPDATE
                name=VALUES(name), name_ko=VALUES(name_ko), price=VALUES(price),
                unit=VALUES(unit), unit_ko=VALUES(unit_ko),
                description=VALUES(description), description_ko=VALUES(description_ko),
                per_unit=VALUES(per_unit)
        """, addon)
    print(f"✅ Seeded {len(ADDONS)} addons")

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

if __name__ == '__main__':
    main()
