# #region type_profiles [C:2] [TYPE Module] [SEMANTICS report, task-type, mapping, profile, fallback]
# @BRIEF Deterministic mapping of plugin/task identifiers to canonical report task types and fallback profile metadata.

from typing import Any

from ...core.logger import belief_scope
from ...models.report import TaskType

# #region PLUGIN_TO_TASK_TYPE [TYPE Data]
# @BRIEF Maps plugin identifiers to normalized report task types.
PLUGIN_TO_TASK_TYPE: dict[str, TaskType] = {
    "llm_dashboard_validation": TaskType.LLM_VERIFICATION,
    "superset-backup": TaskType.BACKUP,
    "superset-migration": TaskType.MIGRATION,
    "documentation": TaskType.DOCUMENTATION,
    "clean-release-compliance": TaskType.CLEAN_RELEASE,
    "clean_release_compliance": TaskType.CLEAN_RELEASE,
}
# #endregion PLUGIN_TO_TASK_TYPE

# #region TASK_TYPE_PROFILES [TYPE Data]
# @BRIEF Profile metadata registry for each normalized task type.
TASK_TYPE_PROFILES: dict[TaskType, dict[str, Any]] = {
    TaskType.LLM_VERIFICATION: {
        "display_label": "LLM Verification",
        "visual_variant": "llm",
        "icon_token": "sparkles",
        "emphasis_rules": ["summary", "status", "next_actions"],
        "fallback": False,
    },
    TaskType.BACKUP: {
        "display_label": "Backup",
        "visual_variant": "backup",
        "icon_token": "archive",
        "emphasis_rules": ["summary", "status", "updated_at"],
        "fallback": False,
    },
    TaskType.MIGRATION: {
        "display_label": "Migration",
        "visual_variant": "migration",
        "icon_token": "shuffle",
        "emphasis_rules": ["summary", "status", "error_context"],
        "fallback": False,
    },
    TaskType.DOCUMENTATION: {
        "display_label": "Documentation",
        "visual_variant": "documentation",
        "icon_token": "file-text",
        "emphasis_rules": ["summary", "status", "details"],
        "fallback": False,
    },
    TaskType.CLEAN_RELEASE: {
        "display_label": "Clean Release",
        "visual_variant": "clean-release",
        "icon_token": "shield-check",
        "emphasis_rules": ["summary", "status", "error_context", "details"],
        "fallback": False,
    },
    TaskType.UNKNOWN: {
        "display_label": "Other / Unknown",
        "visual_variant": "unknown",
        "icon_token": "help-circle",
        "emphasis_rules": ["summary", "status"],
        "fallback": True,
    },
}
# #endregion TASK_TYPE_PROFILES


# #region resolve_task_type [TYPE Function]
# @BRIEF Resolve canonical task type from plugin/task identifier with guaranteed fallback.
# @PRE  plugin_id may be None or unknown.
# @POST  Always returns one of TaskType enum values.
#
# @TEST_CONTRACT  ResolveTaskType ->
# {
#   required_fields: {plugin_id: str},
#   invariants: ["returns TaskType.UNKNOWN for missing/unmapped plugin_id"]
# }
# @TEST_FIXTURE  valid_plugin -> {"plugin_id": "superset-migration"}
# @TEST_EDGE  empty_plugin -> {"plugin_id": ""}
# @TEST_EDGE  none_plugin -> {"plugin_id": None}
# @TEST_EDGE  unknown_plugin -> {"plugin_id": "invalid-plugin"}
# @TEST_INVARIANT  fallback_to_unknown -> verifies: [empty_plugin, none_plugin, unknown_plugin]
def resolve_task_type(plugin_id: str | None) -> TaskType:
    with belief_scope("resolve_task_type"):
        normalized = (plugin_id or "").strip()
        if not normalized:
            return TaskType.UNKNOWN
        return PLUGIN_TO_TASK_TYPE.get(normalized, TaskType.UNKNOWN)


# #endregion resolve_task_type


# #region get_type_profile [TYPE Function]
# @BRIEF Return deterministic profile metadata for a task type.
# @PRE  task_type may be known or unknown.
# @POST  Returns a profile dict and never raises for unknown types.
#
# @TEST_CONTRACT  GetTypeProfile ->
# {
#   required_fields: {task_type: TaskType},
#   invariants: ["returns a valid metadata dictionary even for UNKNOWN"]
# }
# @TEST_FIXTURE  valid_profile -> {"task_type": "migration"}
# @TEST_EDGE  missing_profile -> {"task_type": "some_new_type"}
# @TEST_INVARIANT  always_returns_dict -> verifies: [valid_profile, missing_profile]
def get_type_profile(task_type: TaskType) -> dict[str, Any]:
    with belief_scope("get_type_profile"):
        return TASK_TYPE_PROFILES.get(task_type, TASK_TYPE_PROFILES[TaskType.UNKNOWN])


# #endregion get_type_profile

# #endregion type_profiles
