"""Whether the player's analysis consent allows running an analysis.""" from uuid import UUID from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession from app.modules.settings.models import ConsentEvent async def analysis_consent_blocked(db: AsyncSession, account_id: UUID, require_accepted: bool) -> bool: """True when the latest analysis consent is a withdrawal, or (when required) there is no acceptance.""" action = await db.scalar( select(ConsentEvent.action) .where(ConsentEvent.account_id == account_id, ConsentEvent.category == "analysis") .order_by(ConsentEvent.created_at.desc(), ConsentEvent.id.desc()).limit(1)) return action == "withdrawn" or (require_accepted and action is None)