import asyncio
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker, AsyncSession
from app.core.database import DATABASE_URL
from app.models.models import Voucher, VoucherBatch, HotspotProfile
from sqlalchemy import select

async def clean_db_only():
    engine = create_async_engine(DATABASE_URL)
    async_session = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)

    async with async_session() as db:
        print("Clearing vouchers, batches, and profiles from database...")
        vouchers = (await db.execute(select(Voucher))).scalars().all()
        for v in vouchers:
            await db.delete(v)

        batches = (await db.execute(select(VoucherBatch))).scalars().all()
        for b in batches:
            await db.delete(b)

        profiles = (await db.execute(select(HotspotProfile))).scalars().all()
        for p in profiles:
            await db.delete(p)

        await db.commit()
        print("Database fully cleaned!")

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