# app/workers/catalog_filler.py
import asyncio
from sqlalchemy.ext.asyncio import AsyncSession
from app.db.session import SessionLocal
from app.models.asset import AssetCatalog
from sqlalchemy import select

class CatalogFiller:
    @staticmethod
    async def seed_initial_data():
        """Alapértelmezett márkák és típusok feltöltése (Példa)."""
        initial_data = [
            {"make": "Audi", "model": "A4", "generation": "B8 (2008-2015)", "engine_variant": "2.0 TDI (150 LE)", "fuel_type": "Diesel"},
            {"make": "BMW", "model": "3 Series", "generation": "F30 (2012-2019)", "engine_variant": "320d (190 LE)", "fuel_type": "Diesel"},
            {"make": "Volkswagen", "model": "Passat", "generation": "B8 (2014-)", "engine_variant": "2.0 TDI (150 LE)", "fuel_type": "Diesel"}
        ]
        
        async with SessionLocal() as db:
            for item in initial_data:
                # Ellenőrizzük, létezik-e már
                stmt = select(AssetCatalog).where(
                    AssetCatalog.make == item["make"],
                    AssetCatalog.model == item["model"],
                    AssetCatalog.engine_variant == item["engine_variant"]
                )
                exists = (await db.execute(stmt)).scalar_one_or_none()
                
                if not exists:
                    db.add(AssetCatalog(**item))
            
            await db.commit()
            print("Catalog seeding complete.")

if __name__ == "__main__":
    asyncio.run(CatalogFiller.seed_initial_data())