"""
ShelfAI bundled skills.

Skills are prompt/instruction files that integrate ShelfAI into
specific AI agent platforms. They ship as package data so they're
accessible after `pip install shelfai`.

Usage:
    # Print the Claude skill to stdout
    shelfai skill --show claude

    # Programmatic access
    from shelfai.skills import get_skill_path, get_skill_content
    path = get_skill_path("claude")
    content = get_skill_content("claude")
"""

from importlib import resources
from pathlib import Path


def get_skill_path(name: str) -> Path:
    """Return the filesystem path to a bundled skill's SKILL.md.

    Args:
        name: Skill name (e.g. "claude")

    Returns:
        Path to the SKILL.md file

    Raises:
        FileNotFoundError: If the skill doesn't exist
    """
    # Python 3.9+ compatible
    try:
        ref = resources.files("shelfai.skills") / name / "SKILL.md"
        path = Path(str(ref))
    except (TypeError, FileNotFoundError):
        path = Path(__file__).parent / name / "SKILL.md"

    if not path.exists():
        available = list_skills()
        raise FileNotFoundError(
            f"Skill '{name}' not found. Available skills: {', '.join(available) or '(none)'}"
        )
    return path


def get_skill_content(name: str) -> str:
    """Return the content of a bundled skill.

    Args:
        name: Skill name (e.g. "claude")

    Returns:
        Full text of the SKILL.md file
    """
    return get_skill_path(name).read_text(encoding="utf-8")


def list_skills() -> list[str]:
    """Return names of all bundled skills."""
    skills_dir = Path(__file__).parent
    return sorted(
        d.name
        for d in skills_dir.iterdir()
        if d.is_dir() and (d / "SKILL.md").exists()
    )
