using Xunit;
using Neta.Tray;

public class RuntimeInfoStoreTests
{
    [Fact]
    public void Reads_data_dir_from_config_yaml_and_runtime_info()
    {
        var config = "server:\n  port: 8003\ndata:\n  dir: \"D:\\\\NetaData\"\n";
        var runtimeInfo = "{\"pid\":123,\"ready\":true,\"controlBaseUrl\":\"http://127.0.0.1:8011/base/runtime\",\"controlSecret\":\"secret-abc\"}";

        var resolved = RuntimeInfoStore.ParseConfigAndRuntimeInfo(config, runtimeInfo);

        Assert.Equal(@"D:\NetaData", resolved.DataDir);
        Assert.Equal("http://127.0.0.1:8011/base/runtime", resolved.ControlBaseUrl);
        Assert.Equal("secret-abc", resolved.ControlSecret);
    }

    [Fact]
    public void LoadFromInstalledConfig_returns_null_when_config_missing()
    {
        var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
        Directory.CreateDirectory(tempDir);

        var loaded = RuntimeInfoStore.LoadFromInstalledConfig(tempDir);

        Assert.Null(loaded);
    }
}
