"""Interview Design modes + final-evaluation mode behavior."""

from __future__ import annotations

import pytest
from fastapi.testclient import TestClient

from app.config import get_settings
from app.main import app

client = TestClient(app)
HEADERS = {"X-Internal-Token": get_settings().internal_api_token}
AUTH = {**HEADERS, "X-Company-Id": "co-modes", "X-User-Id": "u-modes"}
WF = "/api/v1/interview-workflows"


@pytest.fixture(autouse=True)
def _force_local(monkeypatch: pytest.MonkeyPatch):
    monkeypatch.setattr("app.llm._provider_available", lambda _name: False)


def test_design_accepts_text_voice_video() -> None:
    for mode in ("text", "voice", "video"):
        res = client.post(
            WF,
            headers=AUTH,
            json={
                "title": f"{mode} interview",
                "role": "Backend Developer",
                "skills": ["Python"],
                "mode": mode,
                "durationMinutes": 30,
            },
        )
        assert res.status_code == 200, res.text
        assert res.json()["mode"] == mode


def test_design_rejects_invalid_mode() -> None:
    res = client.post(
        WF,
        headers=AUTH,
        json={
            "title": "Bad mode",
            "role": "Backend Developer",
            "mode": "AI",
            "durationMinutes": 30,
        },
    )
    assert res.status_code == 422


def test_evaluate_answer_endpoint_removed() -> None:
    res = client.post(
        "/api/v1/interviews/evaluate-answer",
        headers=HEADERS,
        json={
            "interview_mode": "text",
            "role_title": "Backend Engineer",
            "question": "Explain caching",
            "candidate_answer": "Redis with TTL",
        },
    )
    assert res.status_code == 404


def test_final_evaluation_accepts_all_modes() -> None:
    for mode in ("text", "voice", "video"):
        res = client.post(
            "/api/v1/interviews/final-evaluation",
            headers=HEADERS,
            json={
                "interview_mode": mode,
                "role_title": "Backend Engineer",
                "job_description": "Build APIs with FastAPI and Redis.",
                "required_skills": ["Redis", "FastAPI"],
                "qa_items": [
                    {
                        "question": "How do you cache hot reads?",
                        "answer": "I use Redis with TTL for FastAPI hot paths.",
                        "skill_tags": ["Redis", "FastAPI"],
                    }
                ],
            },
        )
        assert res.status_code == 200, res.text
        body = res.json()
        assert body["interview_mode"] == mode
        assert body["overall_score"] is not None
