using Inspectron.Epson.Templates.Configuration;

namespace Inspectron.Epson.Templates.Tests.Configuration;

public class PrinterProfileTests
{
    [Fact]
    public void Default_Profile_HasExpectedValues()
    {
        var profile = PrinterProfile.Default;

        Assert.Equal("default", profile.Id);
        Assert.Equal(48, profile.LineWidth);
        Assert.Equal(24, profile.BigLineWidth);
        Assert.False(profile.SupportsRed);
    }
}

public class PrinterProfileRegistryTests
{
    [Fact]
    public void GetProfile_TmT30III_ReturnsCorrectProfile()
    {
        var registry = new PrinterProfileRegistry();
        var profile = registry.GetProfile(0x01);

        Assert.Equal("tm-t30iii", profile.Id);
        Assert.Equal(48, profile.LineWidth);
        Assert.Equal(24, profile.BigLineWidth);
        Assert.False(profile.SupportsRed);
    }

    [Fact]
    public void GetProfile_TmU220II_0x0D_ReturnsCorrectProfile()
    {
        var registry = new PrinterProfileRegistry();
        var profile = registry.GetProfile(0x0D);

        Assert.Equal("tm-u220ii", profile.Id);
        Assert.Equal(33, profile.LineWidth);
        Assert.Equal(20, profile.BigLineWidth);
        Assert.True(profile.SupportsRed);
    }

    [Fact]
    public void GetProfile_TmU220II_0x13_ReturnsCorrectProfile()
    {
        var registry = new PrinterProfileRegistry();
        var profile = registry.GetProfile(0x13);

        Assert.Equal("tm-u220ii", profile.Id);
        Assert.Equal(33, profile.LineWidth);
        Assert.Equal(20, profile.BigLineWidth);
        Assert.True(profile.SupportsRed);
    }

    [Fact]
    public void GetProfile_UnknownPrinter_ReturnsDefault()
    {
        var registry = new PrinterProfileRegistry();
        var profile = registry.GetProfile(0xFF);

        Assert.Equal(PrinterProfile.Default.LineWidth, profile.LineWidth);
    }

    [Fact]
    public void GetProfile_ByName_ReturnsCorrectProfile()
    {
        var registry = new PrinterProfileRegistry();
        var profile = registry.GetProfile("tm-t30iii");

        Assert.Equal("tm-t30iii", profile.Id);
    }

    [Fact]
    public void Register_CustomProfile_CanBeRetrieved()
    {
        var registry = new PrinterProfileRegistry();
        var customProfile = new PrinterProfile("custom", "Custom Printer", 40, 20, true);
        registry.Register(0xAA, customProfile);

        var retrieved = registry.GetProfile(0xAA);
        Assert.Equal("custom", retrieved.Id);
    }

    [Fact]
    public void GetAllProfiles_ReturnsDistinctProfiles()
    {
        var registry = new PrinterProfileRegistry();
        var profiles = registry.GetAllProfiles().ToList();

        // Should have TM-T30III and TM-U220II (distinct)
        Assert.Equal(2, profiles.Count);
    }
}
