using ClaudeDo.Worker.Prime;

namespace ClaudeDo.Worker.Tests.Prime;

public class DailyPrepPromptTests
{
    [Fact]
    public void Build_prompt_contains_cap_and_date()
    {
        var prompt = DailyPrepPrompt.BuildPrompt(maxTasks: 5, today: new DateOnly(2026, 6, 3));
        Assert.Contains("5", prompt);
        Assert.Contains("2026-06-03", prompt);
        Assert.Contains("get_daily_prep_candidates", prompt);
        Assert.Contains("set_my_day", prompt);
        Assert.Contains("preparing my workday", prompt);
    }

    [Fact]
    public void Build_prompt_without_override_matches_the_plain_render()
    {
        var today = new DateOnly(2026, 6, 3);
        var expected = ClaudeDo.Data.PromptFiles.Render(
            ClaudeDo.Data.PromptKind.DailyPrep,
            new Dictionary<string, string> { ["date"] = "2026-06-03", ["maxTasks"] = "5" });

        var prompt = DailyPrepPrompt.BuildPrompt(maxTasks: 5, today: today);

        Assert.Equal(expected, prompt);
    }

    [Fact]
    public void Build_prompt_appends_override_as_an_additional_paragraph()
    {
        var today = new DateOnly(2026, 6, 3);
        var baseline = DailyPrepPrompt.BuildPrompt(maxTasks: 5, today: today);

        var prompt = DailyPrepPrompt.BuildPrompt(maxTasks: 5, today: today,
            promptOverride: "Also prioritize anything tagged #urgent.");

        Assert.StartsWith(baseline, prompt);
        Assert.Contains("Also prioritize anything tagged #urgent.", prompt);
    }

    [Fact]
    public void Build_prompt_treats_whitespace_only_override_as_absent()
    {
        var today = new DateOnly(2026, 6, 3);
        var baseline = DailyPrepPrompt.BuildPrompt(maxTasks: 5, today: today);

        var prompt = DailyPrepPrompt.BuildPrompt(maxTasks: 5, today: today, promptOverride: "   ");

        Assert.Equal(baseline, prompt);
    }

    [Fact]
    public void Build_args_allows_only_the_two_tools()
    {
        var args = DailyPrepPrompt.BuildArgs(maxTurns: 30);
        Assert.Contains("--output-format", args);
        Assert.Contains("stream-json", args);
        Assert.Contains("--max-turns", args);
        Assert.Contains("30", args);
        Assert.Contains("--allowedTools", args);
        Assert.Contains("mcp__claudedo__get_daily_prep_candidates", args);
        Assert.Contains("mcp__claudedo__set_my_day", args);
    }
}
