export class PromptManager {  
  static async loadPrompt(name: string): Promise<string> {
    try {
      // Load .txt file directly from prompts directory
      const promptPath = new URL(`../prompts/${name}.txt`, import.meta.url);
      const file = Bun.file(promptPath);
      const content = await file.text();
      
      if (!content.trim()) {
        throw new Error(`Prompt file ${name}.txt is empty`);
      }
      
      return content;
    } catch (error) {
      throw new Error(`Failed to load prompt: ${name}.txt. Error: ${error}`);
    }
  }
  
  static interpolate(template: string, variables: Record<string, any>): string {
    let result = template;
    
    // Replace {variable} with actual values
    for (const [key, value] of Object.entries(variables)) {
      const regex = new RegExp(`{${key}}`, 'g');
      result = result.replace(regex, String(value));
    }
    
    // Handle conditional blocks: {condition ? "text" : ""}
    result = result.replace(/\{([^}]+)\s*\?\s*"([^"]+)"\s*:\s*"([^"]*)"\}/g, (_, condition, trueText, falseText) => {
      const conditionValue = variables[condition.trim()];
      return conditionValue ? trueText : falseText;
    });
    
    return result;
  }
}