namespace ClaudeDo.Data;

public enum PromptKind { System, Planning, Agent }

public static class PromptFiles
{
    public static string Root => Path.Combine(Paths.AppDataRoot(), "prompts");

    public static string PathFor(PromptKind kind) => kind switch
    {
        PromptKind.System => Path.Combine(Root, "system.md"),
        PromptKind.Planning => Path.Combine(Root, "planning.md"),
        PromptKind.Agent => Path.Combine(Root, "agent.md"),
        _ => throw new ArgumentOutOfRangeException(nameof(kind))
    };

    public static void EnsureExists(PromptKind kind)
    {
        Directory.CreateDirectory(Root);
        var path = PathFor(kind);
        if (File.Exists(path)) return;
        File.WriteAllText(path, DefaultFor(kind));
    }

    public static string? ReadOrNull(PromptKind kind)
    {
        var path = PathFor(kind);
        if (!File.Exists(path)) return null;
        var content = File.ReadAllText(path).Trim();
        return string.IsNullOrEmpty(content) ? null : content;
    }

    private static string DefaultFor(PromptKind kind) => kind switch
    {
        PromptKind.System =>
            "# System Prompt\n\n" +
            "Baseline instructions appended to every task run.\n" +
            "Edit this file to inject project-wide rules (style, conventions, hard constraints).\n",
        PromptKind.Planning =>
            "You are a planning assistant for ClaudeDo.\n" +
            "Your role is to help break down a task into smaller, actionable subtasks.\n" +
            "Your final goal WILL ALWAYS be the creation of Subtasks.\n\n" +
            "ALWAYS invoke the `superpowers:brainstorming` skill via the Skill tool at the\n" +
            "start of every planning session, and follow its process end-to-end. It guides\n" +
            "you through clarifying questions, approach exploration, and design approval\n" +
            "BEFORE any subtasks are created. Do not create child tasks until the user has\n" +
            "approved a design.\n\n" +
            "NEVER change files yourself.\n\n" +
            "ALWAYS use the available MCP tools (mcp__claudedo__*) to create child tasks once\n" +
            "the design is approved. When you are done planning, finalize the session.\n\n" +
            "Be concise and focused. Each subtask should be independently executable.\n",
        PromptKind.Agent =>
            "# Agent Prompt\n\n" +
            "Appended to the system prompt for tasks tagged \"agent\" (auto-queued runs).\n" +
            "Use this for autonomous-execution rules that don't apply to manual runs.\n",
        _ => ""
    };
}
