using ClaudeDo.Worker.Tickets;
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;

namespace ClaudeDo.Worker.Tests.Tickets;

public sealed class TicketStatusMapTests
{
    [Theory]
    [InlineData(TaskStatus.Running, 2)]
    [InlineData(TaskStatus.WaitingForReview, 2)]
    [InlineData(TaskStatus.Done, 3)]
    public void Maps_the_three_states_we_report(TaskStatus status, int expected)
        => Assert.Equal(expected, TicketStatusMap.ToTicketStatus(status));

    [Theory]
    [InlineData(TaskStatus.Idle)]
    [InlineData(TaskStatus.Queued)]
    [InlineData(TaskStatus.WaitingForChildren)]
    [InlineData(TaskStatus.Failed)]
    [InlineData(TaskStatus.Cancelled)]
    public void Everything_else_writes_nothing(TaskStatus status)
        => Assert.Null(TicketStatusMap.ToTicketStatus(status));

    [Fact]
    public void Never_writes_Offen()
    {
        foreach (var status in Enum.GetValues<TaskStatus>())
            Assert.NotEqual(1, TicketStatusMap.ToTicketStatus(status));
    }

    [Theory]
    [InlineData("bandel:1234", 1234)]
    [InlineData("BANDEL:7", 7)]
    public void Parses_a_bandel_ref(string reference, int expected)
        => Assert.Equal(expected, TicketStatusMap.ParseBandelTicketId(reference));

    [Theory]
    [InlineData(null)]
    [InlineData("")]
    [InlineData("1234")]
    [InlineData("jira:ABC-1")]
    [InlineData("bandel:")]
    [InlineData("bandel:abc")]
    public void Rejects_anything_else(string? reference)
        => Assert.Null(TicketStatusMap.ParseBandelTicketId(reference));
}
