from __future__ import annotations

from dataclasses import dataclass, field

from niannian.skills.registry import SkillRecord


@dataclass
class SkillInjectContext:
    mode: str | None = None
    vp_id: str | None = None
    equipped_skill_names: list[str] = field(default_factory=list)


def skill_matches_context(skill: SkillRecord, context: SkillInjectContext | None) -> bool:
    """Return whether *skill* should be injected for the given inject context."""
    if context is None:
        return skill.kind != "persona" and skill.scope == "global"

    if skill.scope == "global":
        return skill.kind != "persona"

    if skill.scope == "vp":
        if not context.vp_id:
            return False
        return skill.name in context.equipped_skill_names

    if skill.scope == "mode":
        if not context.mode:
            return False
        from niannian.skills.mode_registry import resolve_mode_skill_names

        return skill.name in resolve_mode_skill_names(context.mode)

    return False
