using ClaudeDo.Data.Filtering;
using ClaudeDo.Data.Models;
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;

namespace ClaudeDo.Data.Tests.Filtering;

public sealed class PlanningRulesTests
{
    [Theory]
    [InlineData(PlanningPhase.None,      false)]
    [InlineData(PlanningPhase.Active,    true)]
    [InlineData(PlanningPhase.Finalized, true)]
    public void IsPlanningParent_reflects_phase(PlanningPhase phase, bool expected)
    {
        var t = TaskFactory.Make("p", phase: phase);
        Assert.Equal(expected, PlanningRules.IsPlanningParent(t));
    }

    [Fact]
    public void HasMatchingChild_true_when_a_child_matches()
    {
        var parent = TaskFactory.Make("p", phase: PlanningPhase.Active);
        var child  = TaskFactory.Make("c", parentId: "p", status: TaskStatus.Queued);
        var all    = new List<TaskEntity> { parent, child };

        Assert.True(PlanningRules.HasMatchingChild(parent, all, c => c.Status == TaskStatus.Queued));
    }

    [Fact]
    public void HasMatchingChild_false_when_no_child_matches()
    {
        var parent = TaskFactory.Make("p", phase: PlanningPhase.Active);
        var child  = TaskFactory.Make("c", parentId: "p", status: TaskStatus.Done);
        var all    = new List<TaskEntity> { parent, child };

        Assert.False(PlanningRules.HasMatchingChild(parent, all, c => c.Status == TaskStatus.Queued));
    }

    [Fact]
    public void HasMatchingChild_ignores_other_parents_children()
    {
        var parent      = TaskFactory.Make("p",  phase: PlanningPhase.Active);
        var otherParent = TaskFactory.Make("p2", phase: PlanningPhase.Active);
        var foreignKid  = TaskFactory.Make("c",  parentId: "p2", status: TaskStatus.Queued);
        var all         = new List<TaskEntity> { parent, otherParent, foreignKid };

        Assert.False(PlanningRules.HasMatchingChild(parent, all, c => c.Status == TaskStatus.Queued));
    }
}
