"""Claude (Anthropic) LLM provider."""

import os

from alive.llm.base import LLMProvider


class ClaudeProvider(LLMProvider):
    name = "claude"

    def __init__(self) -> None:
        import anthropic

        api_key = os.environ.get("ALIVE_CLAUDE_KEY") or os.environ.get("ANTHROPIC_API_KEY")
        if not api_key:
            raise ValueError(
                "No Claude API key found.\n\n"
                "Fix: Set your API key with one of:\n"
                "  alive config --claude-key sk-ant-...\n"
                "  export ANTHROPIC_API_KEY=sk-ant-...\n\n"
                "Or switch to a local model: alive config --provider ollama"
            )
        self.client = anthropic.AsyncAnthropic(api_key=api_key)
        self.model = os.environ.get("ALIVE_CLAUDE_MODEL", "claude-sonnet-4-20250514")

    async def complete(self, system_prompt: str, user_prompt: str) -> str:
        response = await self.client.messages.create(
            model=self.model,
            max_tokens=4096,
            system=system_prompt,
            messages=[{"role": "user", "content": user_prompt}],
        )
        return response.content[0].text
