# guardianhub_sdk/agents/services/prompt_manager.py
from guardianhub import get_logger

logger = get_logger(__name__)


# guardianhub_sdk/agents/services/prompt_manager.py

class SovereignPromptManager:
    def resolve_prompt(self, tenant: str, template_id: str, agent: str, category: str, role: str) -> str:
        """
        🚀 THE DIRECTORY RESOLVER:
        Traverses folders from Mission-Specific to Global-Core.
        """
        lookup_paths = [
            # 1. Physical Mission Path (High Priority Override)
            f"tenants/{tenant}/missions/{template_id}/{role}",

            # 2. Specialist Folder
            f"agents/{agent}/{role}",

            # 3. Domain Folder
            f"domains/{category}/{role}",

            # 4. Core System Folder (Standard Fallback)
            f"core/{role}"
        ]

        for path in lookup_paths:
            try:
                # Langfuse treats these paths as the prompt 'name'
                prompt = self.langfuse.get_prompt(path)
                logger.info(f"📁 [PROMPT_FS] Loaded: {path}")
                return prompt.compile()
            except Exception:
                # Silently move to the next folder in the hierarchy
                continue

        return ""  # SDK Hardcoded fallback