using System.Globalization;
using Avalonia;
using Avalonia.Media;
using ClaudeDo.Data.Models;
using ClaudeDo.Ui.Converters;
using Xunit;

namespace ClaudeDo.Ui.Tests;

public class WorkerLogLevelToBrushConverterTests
{
    [Theory]
    [InlineData(WorkerLogLevel.Success, "#FF4CAF50")]
    [InlineData(WorkerLogLevel.Warn,    "#FFFFA726")]
    [InlineData(WorkerLogLevel.Error,   "#FFEF5350")]
    public void Convert_maps_level_to_expected_brush_color(WorkerLogLevel level, string expectedArgb)
    {
        var converter = new WorkerLogLevelToBrushConverter();

        var result = converter.Convert(level, typeof(IBrush), null, CultureInfo.InvariantCulture);

        var solid = Assert.IsType<SolidColorBrush>(result);
        Assert.Equal(expectedArgb.ToLowerInvariant(), $"#{solid.Color.ToUInt32():X8}".ToLowerInvariant());
    }

    [Fact]
    public void Convert_info_returns_a_brush_fallback_when_no_app()
    {
        var converter = new WorkerLogLevelToBrushConverter();

        var result = converter.Convert(WorkerLogLevel.Info, typeof(IBrush), null, CultureInfo.InvariantCulture);

        Assert.IsAssignableFrom<IBrush>(result);
    }

    [Fact]
    public void Convert_unknown_value_returns_unset()
    {
        var converter = new WorkerLogLevelToBrushConverter();

        var result = converter.Convert("not a level", typeof(IBrush), null, CultureInfo.InvariantCulture);

        Assert.Equal(AvaloniaProperty.UnsetValue, result);
    }
}
