from pathlib import Path
import yaml
from krrkt.providers.base import LLMProvider


def _load_system_prompt() -> str:
    # Package data first, then dev config
    prompt_file = Path(__file__).parent.parent / "data" / "prompts" / "analyze.yaml"
    if not prompt_file.exists():
        prompt_file = Path(__file__).parent.parent.parent.parent / "config" / "prompts" / "analyze.yaml"
    with open(prompt_file, encoding="utf-8") as f:
        data = yaml.safe_load(f)
    return data.get("system_prompt", "")


class DeepLayer:
    def __init__(self, provider: LLMProvider):
        self.provider = provider
        self.system_prompt = _load_system_prompt()

    async def analyze(self, text: str, already_found: list[dict] | None = None,
                      model: str | None = None) -> list[dict]:
        if already_found is None:
            already_found = []
        return await self.provider.analyze(text, self.system_prompt, already_found)
