package com.pablotj.ia.chat.boot.application.prompt;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.pablotj.ia.chat.boot.domain.exception.BusinessLogicException;
import java.io.IOException;
import java.io.InputStream;

public class PromptTemplates {

    private static final String BASE_PATH = "/prompts/";
    private static final String DEFAULT_PROFILE = "default";
    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

    /**
     * Loads and returns the full prompts string for the given profile name.
     *
     * @param profileName name of the prompts profile, without extension (e.g. "default")
     * @return full system prompts as String
     */
    public static String get(String profileName) {
        return load(profileName).buildPrompt();
    }

    /**
     * Loads and returns the PromptDefinition for the given profile.
     *
     * @param profileName prompts profile name (e.g. "developer", "minimal")
     * @return PromptDefinition object
     */
    public static PromptDefinition load(String profileName) {
        String filePath = BASE_PATH + profileName + "_prompt.json";
        try (InputStream input = PromptTemplates.class.getResourceAsStream(filePath)) {
            if (input == null) {
                throw new BusinessLogicException("Prompt profile not found: " + filePath);
            }
            return OBJECT_MAPPER.readValue(input, PromptDefinition.class);
        } catch (IOException e) {
            throw new BusinessLogicException("Failed to load prompts profile: " + profileName, e);
        }
    }

    /**
     * Shortcut for default profile.
     */
    public static String getDefault() {
        return get(DEFAULT_PROFILE);
    }

    private PromptTemplates() {
        // Utility class
    }
}