using System.Runtime.InteropServices;
using EpsonPrintService;

namespace Inspectron.Epson.Tests.Configuration;

public class ConfigurationPathsTests
{
    [Fact]
    public void GetConfigPath_uses_opt_dir_on_linux_when_env_unset_and_no_local_file()
    {
        if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) return;
        var previous = Environment.GetEnvironmentVariable("EPSON_CONFIG_PATH");
        Environment.SetEnvironmentVariable("EPSON_CONFIG_PATH", null);
        try
        {
            var path = ConfigurationPaths.GetConfigPath();
            Assert.Equal("/opt/epson-print-service/config.txt", path);
        }
        finally
        {
            Environment.SetEnvironmentVariable("EPSON_CONFIG_PATH", previous);
        }
    }

    [Fact]
    public void EPSON_CONFIG_PATH_override_still_wins()
    {
        var previous = Environment.GetEnvironmentVariable("EPSON_CONFIG_PATH");
        Environment.SetEnvironmentVariable("EPSON_CONFIG_PATH", "/tmp/override.txt");
        try
        {
            var path = ConfigurationPaths.GetConfigPath();
            Assert.Equal("/tmp/override.txt", path);
        }
        finally
        {
            Environment.SetEnvironmentVariable("EPSON_CONFIG_PATH", previous);
        }
    }
}
