"""Shared test fixtures."""

from __future__ import annotations

from types import SimpleNamespace

import pytest


def _role_for_job_id(job_id: str) -> str:
    jid = (job_id or "").lower()
    if "pm" in jid or "product" in jid or "case" in jid:
        return "Product Manager"
    if "clinical" in jid:
        return "Clinical Data Analyst"
    if "general" in jid:
        return "General"
    return "Backend Engineer"


@pytest.fixture(autouse=True)
def _fake_linked_job_from_db(monkeypatch: pytest.MonkeyPatch) -> None:
    """Resolve linked_job without requiring seeded ai_jobs rows."""

    def fake_get_job(job_id: str):
        if not job_id or job_id in {"missing", "job-missing", "does-not-exist"}:
            return None
        role = _role_for_job_id(job_id)
        skills = {
            "Product Manager": ["roadmap", "discovery"],
            "Backend Engineer": ["Python", "FastAPI", "PostgreSQL"],
            "Clinical Data Analyst": ["HIPAA", "SQL"],
            "General": ["logic"],
        }.get(role, ["Python"])
        return SimpleNamespace(
            job_id=job_id,
            role_title=role,
            title=role,
            markdown=(
                f"## {role}\nOwn delivery for this role. "
                f"Skills: {', '.join(skills)}."
            ),
            sections={
                "summary": f"{role} opening",
                "requirements": [f"Experience as {role}"],
                "preferred_skills": skills,
            },
            meta={"skills": skills},
        )

    monkeypatch.setattr("app.services.assessments.ai_hub.get_job", fake_get_job)
