"""Выбор имени системного промпта по sub_intent и answer_mode."""

from __future__ import annotations


class RuntimePromptSelector:
    _CODE_PROMPTS = {
        "ARCHITECTURE": "code_qa_architecture_answer",
        "EXPLAIN": "code_qa_explain_answer",
        "EXPLAIN_LOCAL": "code_qa_explain_local_answer",
        "FIND_ENTRYPOINTS": "code_qa_find_entrypoints_answer",
        "FIND_TESTS": "code_qa_find_tests_answer",
        "GENERAL_QA": "code_qa_general_answer",
        "OPEN_FILE": "code_qa_open_file_answer",
        "TRACE_FLOW": "code_qa_trace_flow_answer",
    }
    _DOCS_INTENT_PROMPTS = {
        "DOCUMENTATION_EXPLAIN": "docs_explain_answer",
        "GENERAL_QA": "docs_general_answer",
    }

    def select(self, *, intent: str = "CODE_QA", sub_intent: str, answer_mode: str) -> str:
        intent_key = (intent or "CODE_QA").upper()
        if intent_key in {"OPENAPI_GENERATION", "OPENAPI_FROM_DOCUMENTATION"}:
            if sub_intent.upper() == "OPENAPI_FRAGMENT_GENERATE":
                return "docs_openapi_fragment_answer"
            return "docs_openapi_answer"
        if intent_key in self._DOCS_INTENT_PROMPTS:
            return self._DOCS_INTENT_PROMPTS[intent_key]
        if answer_mode in {"degraded", "not_found", "insufficient"}:
            return "code_qa_degraded_answer"
        return self._CODE_PROMPTS.get(sub_intent.upper(), "code_qa_explain_answer")
