"""Skill 元数据定义 - Phase 9.1"""

from dataclasses import dataclass, field
from typing import Any


@dataclass
class SkillMetadata:
    """Skill 元数据"""

    id: str = ""  # Skill ID
    name: str = ""  # Skill 名称
    description: str = ""  # 描述
    version: str = "1.0.0"  # 版本
    author: str = ""  # 作者
    tags: list[str] = field(default_factory=list)  # 标签
    triggers: list[str] = field(default_factory=list)  # 触发关键词
    content: str = ""  # Skill 内容（markdown）
    source: str = "local"  # 来源：local, plugin, mcp, bundled
    source_id: str = ""  # 来源 ID
    enabled: bool = True  # 是否启用
    tools: list[str] = field(default_factory=list)  # 关联的工具
    status: str = "active"  # candidate/shadow/active/deprecated/retired
    scope: list[str] = field(default_factory=list)
    effectiveness: float | None = None
    review_after: str | None = None

    def to_dict(self) -> dict[str, Any]:
        return {
            "id": self.id,
            "name": self.name,
            "description": self.description,
            "version": self.version,
            "author": self.author,
            "tags": self.tags,
            "triggers": self.triggers,
            "content": self.content,
            "source": self.source,
            "source_id": self.source_id,
            "enabled": self.enabled,
            "tools": self.tools,
            "status": self.status,
            "scope": self.scope,
            "effectiveness": self.effectiveness,
            "review_after": self.review_after,
        }

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> "SkillMetadata":
        return cls(**data)
