using System.Net;
using System.Net.Http.Json;
using CashLineERP.Contracts.Localization;

namespace CashLineERP.Api.Tests;

public sealed class LocalizationResourceQaTests : IClassFixture<ApiTestFactory>
{
    private readonly HttpClient _client;

    public LocalizationResourceQaTests(ApiTestFactory factory)
    {
        _client = factory.CreateClient();
    }

    [Fact]
    public async Task Localization_Endpoints_Return_Supported_Cultures_And_Arabic_Label_Pack()
    {
        await _client.AuthenticateAsInternalAsync();

        var culturesResponse = await _client.GetAsync("/api/v1/localization/supported-cultures");
        Assert.Equal(HttpStatusCode.OK, culturesResponse.StatusCode);
        var cultures = await culturesResponse.Content.ReadFromJsonAsync<SupportedCultureResponse[]>();
        Assert.NotNull(cultures);
        Assert.Contains(cultures!, item => item.CultureCode == "ar-EG" && item.TextDirectionCode == "RTL");

        var packResponse = await _client.GetAsync("/api/v1/localization/resource-packs/ADMIN_SETUP_PORTAL?cultureCode=ar-EG");
        Assert.Equal(HttpStatusCode.OK, packResponse.StatusCode);
        var pack = await packResponse.Content.ReadFromJsonAsync<LocalizationResourcePackResponse>();
        Assert.NotNull(pack);
        Assert.Equal("RTL", pack!.TextDirectionCode);
        Assert.Equal("نظرة عامة", pack.Resources["nav.overview"]);
        Assert.Equal("الفعالة فقط", pack.Resources["filters.activeOnly"]);
    }
}
