"""Auto-learned skill generated by GPIA."""

from typing import Any, Dict

from skills.base import Skill, SkillCategory, SkillContext, SkillLevel, SkillMetadata, SkillResult

import math

def solve(task: str, context: dict) -> object:
    return math.sqrt(987654321) * math.pi

class AutoLearnedSkill(Skill):
    _cached_metadata: SkillMetadata = None

    def metadata(self) -> SkillMetadata:
        if AutoLearnedSkill._cached_metadata is None:
            AutoLearnedSkill._cached_metadata = SkillMetadata(
                id="auto_learned/using_the_math_tool_you_just_learned_cal_5b64a499",
                name="Auto Learned using_the_math_tool_you_just_learned_cal",
                description="Auto-learned skill for: Using the math tool you just learned, calculate the square root of 987654321 multiplied by pi.",
                category=SkillCategory.AUTOMATION,
                level=SkillLevel.INTERMEDIATE,
                tags=["auto-learned", "drafted"],
            )
        return AutoLearnedSkill._cached_metadata

    def execute(self, input_data: Dict[str, Any], context: SkillContext) -> SkillResult:
        task = input_data.get("task", "")
        payload = input_data.get("context", input_data)
        try:
            result = solve(task, payload)
        except Exception as exc:
            return SkillResult(
                success=False,
                output=None,
                error=str(exc),
                error_code="AUTO_LEARNED_ERROR",
                skill_id=self.metadata().id,
            )
        output = result if isinstance(result, dict) else {"result": result}
        return SkillResult(
            success=True,
            output=output,
            skill_id=self.metadata().id,
        )
