import asyncio
from sqlalchemy import select
from app.core.database import AsyncSessionLocal
from app.models.models import Customer, MikrotikDevice, ODP


async def main():
    async with AsyncSessionLocal() as db:
        devices = (await db.execute(select(MikrotikDevice).order_by(MikrotikDevice.id))).scalars().all()
        for device in devices:
            odp_count = len((await db.execute(select(ODP.id).where(ODP.mikrotik_device_id == device.id))).scalars().all())
            customer_count = len((await db.execute(select(Customer.id).where(Customer.mikrotik_device_id == device.id))).scalars().all())
            print(f"id={device.id}|name={device.name}|odp_refs={odp_count}|customer_refs={customer_count}")


asyncio.run(main())
