using CashLineERP.Application.Localization;
using CashLineERP.Infrastructure.Persistence.Repositories;

namespace CashLineERP.Api.Tests;

public sealed class LocalizationResourceServiceQaTests
{
    [Fact]
    public void Localization_Service_Returns_Arabic_Label_Pack_With_Rtl_Direction()
    {
        using var dbContext = QaDbContextFactory.CreateContext();

        var localizationService = new LocalizationService(new LocalizationResourceRepository(dbContext));

        var pack = localizationService.GetResourcePack("ADMIN_SETUP_PORTAL", "ar-EG");

        Assert.Equal("ADMIN_SETUP_PORTAL", pack.ResourceSetCode);
        Assert.Equal("ar-EG", pack.ResolvedCultureCode);
        Assert.Equal("RTL", pack.TextDirectionCode);
        Assert.Equal("إعدادات الإدارة", pack.Resources["sidebar.title"]);
        Assert.Equal("مسار الاعتماد", pack.Resources["nav.approvalPath"]);
    }

    [Fact]
    public void Localization_Service_Falls_Back_To_Default_English_When_Culture_Is_Not_Available()
    {
        using var dbContext = QaDbContextFactory.CreateContext();

        var localizationService = new LocalizationService(new LocalizationResourceRepository(dbContext));

        var pack = localizationService.GetResourcePack("ADMIN_SETUP_PORTAL", "fr-FR");

        Assert.Equal("fr-FR", pack.RequestedCultureCode);
        Assert.Equal("en-US", pack.ResolvedCultureCode);
        Assert.Equal("LTR", pack.TextDirectionCode);
        Assert.Equal("Admin Setup", pack.Resources["sidebar.title"]);
    }
}
