class AccountUpdate(BaseModel):
    sending_method: str = "api"     # api | smtp
    daily_limit: int = 200
    campaign_limit: int = 200


def _account_out(account: GmailAccount) -> dict:
    t = account.oauth_token
    return {
        "id": account.id,
        "email": account.email,
        "display_name": account.display_name,
        "status": account.status,
        "sending_method": account.sending_method,
        "daily_limit": account.daily_limit,
        "campaign_limit": account.campaign_limit,
        "sends_today": account.sends_today,
        "last_success_at": account.last_success_at.isoformat() if account.last_success_at else None,
        "error_count": account.error_count,
        "last_error": (account.last_error or "")[:300],
        "cooldown_until": account.cooldown_until.isoformat() if account.cooldown_until else None,
        "has_refresh_token": bool(t and t.refresh_token_enc),
        "token_expires_at": t.expires_at.isoformat() if t and t.expires_at else None,
        "authorized": account.status == "authorized",
    }


@router.get("/accounts")
async def list_accounts(user: User = Depends(get_current_user),
                        db: AsyncSession = Depends(get_db)):
    rows = (await db.execute(select(GmailAccount).where(
=== recipients router serializers ===
37:    return {"id": r.id, "email": r.email, "first_name": r.first_name, "last_name": r.last_name,
52:    return {"lists": [{"id": l.id, "name": l.name, "description": l.description,
63:    return {"id": rl.id, "name": rl.name}
101:    return {"filename": file.filename, "headers": headers,
159:    return {"ok": True, **rpt.summary(), "list_id": list_id}
187:        return {"ok": True, "recipient": _rec_out(rec)}
188:    return {"ok": False, "summary": rpt.summary(),
204:    return {"total": total, "page": page, "recipients": [_rec_out(r) for r in rows]}
219:    return {"ok": True}
231:    return {"ok": True}
243:    return {"ok": True, "list_id": list_id}
