using RioJoy.Core.Profiles;
using Xunit;

namespace RioJoy.Core.Tests.Profiles;

public class RioIniImporterTests
{
    private const string Sample = """
        [Plasma]
        Greeting = RIOvJoy2 v.03

        [Desktop]
        File = C:\games\RIO\VWE2.bmp

        [JoyStick]
        invertX = false
        invertY = true
        enableZR = false

        ; comment line
        [Buttons]
        RIO00 = 0x8049
        RIO01 = 0x805A
        RIO16 = 0x0
        RIO50 = 33353
        """;

    [Fact]
    public void Imports_ButtonsAsAddresses()
    {
        RioProfile p = RioIniImporter.Import(Sample, "VWE2");

        Assert.Equal("VWE2", p.Name);
        Assert.Equal(0x8049, p.Buttons[0x00]);
        Assert.Equal(0x805A, p.Buttons[0x01]);
        Assert.Equal(33353, p.Buttons[0x50]); // keypad-0 address, decimal value
        Assert.False(p.Buttons.ContainsKey(0x16)); // 0x0 entries are skipped
    }

    [Fact]
    public void Imports_PlasmaAndCalibration()
    {
        RioProfile p = RioIniImporter.Import(Sample);

        Assert.Equal("RIOvJoy2 v.03", p.PlasmaGreeting);
        Assert.Equal(@"C:\games\RIO\VWE2.bmp", p.WallpaperPath);
        Assert.False(p.Calibration.InvertX);
        Assert.True(p.Calibration.InvertY);
        Assert.False(p.Calibration.EnableZR);
    }

    [Fact]
    public void EnableZR_DefaultsTrue_WhenAbsent()
    {
        RioProfile p = RioIniImporter.Import("[JoyStick]\ninvertX = true");
        Assert.True(p.Calibration.EnableZR);
    }
}
