"""Orchestrates the full analysis pipeline: matching -> flow -> assessment.""" from uuid import UUID from sqlalchemy.ext.asyncio import AsyncSession from app.models.case import Case, CaseStatus from app.services.matching_service import run_matching from app.services.assessment_service import assess_case from app.services.case_service import recalculate_case_total async def run_analysis_sync(case_id: UUID, db: AsyncSession) -> None: """Run the full analysis pipeline synchronously (fallback when Celery is down).""" case = await db.get(Case, case_id) if not case: return case.status = CaseStatus.analyzing await db.flush() # Step 1: Matching & dedup self_accounts = _extract_self_accounts(case) await run_matching(case_id, self_accounts, db) # Step 2: Assessment await assess_case(case_id, db) # Step 3: Recalculate total await recalculate_case_total(case_id, db) case.status = CaseStatus.reviewing await db.flush() def _extract_self_accounts(case: Case) -> list[str]: """Extract known self-account identifiers from case context. In a full implementation this would come from user input or a dedicated 'victim accounts' table. For now we return an empty list and rely on heuristic rules. """ return []