"""看 task assignee_id / created_by 是否對得上 user.id。"""
import os, sys
ENV = "/volume1/homes/robertsu/coba/app/.env"
if os.path.exists(ENV):
    for l in open(ENV):
        if "=" in l and not l.startswith("#"):
            k,v = l.strip().split("=",1); os.environ.setdefault(k,v)
sys.path.insert(0,"/volume1/homes/robertsu/coba/app")

import asyncio
from sqlalchemy import select
from app.database import AsyncSessionLocal
from app.models.task import Task
from app.models.user import User


async def main():
    async with AsyncSessionLocal() as db:
        users = (await db.execute(select(User).where(User.deleted_at.is_(None)))).scalars().all()
        print(f"=== 全部 active users ({len(users)}) ===")
        for u in users:
            tag = "active" if u.is_active else "inactive"
            print(f"  id={str(u.id)[:8]} name={u.display_name!r:25} role={u.role:6} email={u.email!r} {tag}")

        tasks = (await db.execute(select(Task).where(Task.deleted_at.is_(None)))).scalars().all()
        print(f"\n=== 活著任務 ({len(tasks)}) ===")
        for t in tasks:
            aid = str(t.assignee_id)[:8] if t.assignee_id else "(none)"
            cid = str(t.created_by)[:8] if t.created_by else "(none)"
            print(f"  '{t.title[:30]}' status={t.status} assignee={aid} created_by={cid}")


asyncio.run(main())
