"""Claude platform adapter."""

import os
from pathlib import Path

from pb_spec.platforms.base import SKILL_METADATA, Platform


class ClaudePlatform(Platform):
    """Claude Code — skills as .claude/skills/<name>/SKILL.md."""

    name = "claude"

    def get_skill_path(self, cwd: Path, skill_name: str, global_install: bool = False) -> Path:
        if global_install:
            claude_home = Path(
                os.environ.get("CLAUDE_CONFIG_DIR", str(Path.home() / ".claude"))
            ).expanduser()
            return claude_home / "skills" / skill_name / "SKILL.md"
        return cwd / ".claude" / "skills" / skill_name / "SKILL.md"

    def render_skill(self, skill_name: str, template_content: str) -> str:
        description = SKILL_METADATA.get(skill_name, "").replace('"', '\\"')
        frontmatter = f'---\nname: {skill_name}\ndescription: "{description}"\n---\n\n'
        return frontmatter + template_content
