import asyncio
from sqlalchemy import text
from app.db.session import engine

# 200+ Autó márka és Motor márkák discovery listája
DATA = {
    "CAR": [
        "Toyota", "Volkswagen", "Ford", "BMW", "Mercedes-Benz", "Audi", "Honda", "Hyundai", "Kia", "Mazda",
        "Nissan", "Opel", "Peugeot", "Renault", "Skoda", "Suzuki", "Volvo", "Fiat", "Dacia", "Citroen",
        "Tesla", "Lexus", "Alfa Romeo", "Jaguar", "Land Rover", "Mitsubishi", "Subaru", "Seat", "Cupra",
        "Jeep", "Chevrolet", "Cadillac", "Buick", "GMC", "Dodge", "Ram", "Chrysler", "Acura", "Infiniti",
        "Lincoln", "Porsche", "Mini", "Smart", "Bentley", "Rolls-Royce", "Lamborghini", "Ferrari", "Maserati",
        "Aston Martin", "Bugatti", "Lotus", "McLaren", "Polestar", "Genesis", "BYD", "Geely", "Chery", "MG",
        "Lada", "Iveco", "Isuzu", "SsangYong", "Rover", "Saab", "Lancia", "Pontiac", "Saturn", "Hummer", "Oldsmobile"
    ],
    "MOTORCYCLE": [
        "Honda", "Yamaha", "Kawasaki", "Suzuki", "BMW Motorrad", "Harley-Davidson", "Ducati", "KTM", "Triumph",
        "Royal Enfield", "Indian", "Aprilia", "Moto Guzzi", "Vespa", "Piaggio", "MV Agusta", "Norton", "Husqvarna",
        "Benelli", "Bimota", "Beta", "Gas Gas", "Sherco", "CF Moto", "Hyosung", "Keeway", "SYM", "Kymco", "Bajaj", "Zero"
    ],
    "TRUCK": ["Scania", "Volvo Trucks", "MAN", "DAF", "Iveco", "Mercedes-Benz Trucks", "Renault Trucks", "MACK", "Peterbilt", "Kenworth"],
    "VAN": ["Ford Commercial", "Volkswagen Commercial", "Iveco Daily", "Mercedes-Benz Vans", "Fiat Professional"]
}

async def seed():
    async with engine.begin() as conn:
        print("🔍 Adatok szinkronizálása...")
        
        # 1. Kategóriák
        for cat in DATA.keys():
            await conn.execute(text("INSERT INTO data.vehicle_categories (name) VALUES (:n) ON CONFLICT (name) DO NOTHING"), {"n": cat})
        
        res = await conn.execute(text("SELECT id, name FROM data.vehicle_categories"))
        cat_map = {row.name: row.id for row in res}
        
        # 2. Márkák feltöltése
        count = 0
        for cat_name, brands in DATA.items():
            cat_id = cat_map[cat_name]
            for brand in brands:
                await conn.execute(text(
                    "INSERT INTO data.vehicle_brands (category_id, name) VALUES (:c, :n) ON CONFLICT DO NOTHING"
                ), {"c": cat_id, "n": brand})
                count += 1
        
        print(f"✅ SIKER: {count} márka rögzítve az adatbázisban!")

if __name__ == "__main__":
    asyncio.run(seed())
