"""Prompt loader utility for readme-writer."""

import os
from pathlib import Path
from importlib import resources


class PromptLoader:
    """Utility class for loading prompts from files."""
    
    def __init__(self):
        """Initialize the prompt loader."""
        pass
    
    def load_prompt(self, prompt_file: str) -> str:
        """Load a prompt from a file."""
        try:
            # Try to load from package resources first (for installed packages)
            with resources.files("prompts").joinpath(prompt_file).open('r', encoding='utf-8') as f:
                return f.read().strip()
        except (ImportError, FileNotFoundError):
            # Fallback to relative path (for development)
            current_file = Path(__file__)
            prompt_path = current_file.parent.parent / "prompts" / prompt_file
            
            if not prompt_path.exists():
                raise FileNotFoundError(f"Prompt file not found: {prompt_file}")
            
            with open(prompt_path, 'r', encoding='utf-8') as f:
                return f.read().strip()
    
    def load_full_prompt(self) -> str:
        """Load the full generation prompt."""
        return self.load_prompt("full-prompt.txt") 