import asyncio
import logging
from dotenv import load_dotenv
from sqlalchemy import select

load_dotenv()

from app.core.database import AsyncSessionLocal
from app.core.onboarding import refresh_customer_online_status
from app.models.models import Customer

logging.getLogger("sqlalchemy.engine").setLevel(logging.WARNING)


async def main():
    async with AsyncSessionLocal() as db:
        customers = (await db.execute(
            select(Customer).where(Customer.is_archived == False).order_by(Customer.id)
        )).scalars().all()
        for customer in customers:
            state = await refresh_customer_online_status(customer, db)
            print(f"{customer.id}|{customer.name}|{state}|{customer.provisioning_message}")


asyncio.run(main())
