using ClaudeDo.Localization;

namespace ClaudeDo.Localization.Tests;

public class LocaleJsonTests
{
    private const string Sample = """
    {
      "metadata": { "code": "en", "name": "English" },
      "settings": { "save": "Save", "general": { "model": "Model" } },
      "tasks": { "addPlaceholder": "Add a task" }
    }
    """;

    [Fact]
    public void Parse_reads_metadata()
    {
        var f = LocaleJson.Parse(Sample);
        Assert.Equal("en", f.Code);
        Assert.Equal("English", f.Name);
    }

    [Fact]
    public void Parse_flattens_nested_keys_to_dot_paths()
    {
        var f = LocaleJson.Parse(Sample);
        Assert.Equal("Save", f.Strings["settings.save"]);
        Assert.Equal("Model", f.Strings["settings.general.model"]);
        Assert.Equal("Add a task", f.Strings["tasks.addPlaceholder"]);
    }

    [Fact]
    public void Parse_excludes_metadata_from_strings()
    {
        var f = LocaleJson.Parse(Sample);
        Assert.False(f.Strings.ContainsKey("metadata.code"));
    }
}
