// EN: Adapter that bridges API-layer ITenantProvider to Infrastructure-layer IWalletTenantProvider.
// VI: Adapter kết nối ITenantProvider tầng API đến IWalletTenantProvider tầng Infrastructure.

using WalletService.Infrastructure;

namespace WalletService.API.Infrastructure.Tenant;

/// <summary>
/// EN: Adapts the API-layer ITenantProvider to the Infrastructure IWalletTenantProvider interface.
///     Wallet service uses user_id as primary tenant key.
/// VI: Chuyển đổi ITenantProvider tầng API sang interface IWalletTenantProvider tầng Infrastructure.
///     Wallet service sử dụng user_id làm tenant key chính.
/// </summary>
public class WalletTenantProviderAdapter : IWalletTenantProvider
{
    private readonly ITenantProvider _tenantProvider;

    public WalletTenantProviderAdapter(ITenantProvider tenantProvider)
    {
        _tenantProvider = tenantProvider ?? throw new ArgumentNullException(nameof(tenantProvider));
    }

    public Guid? GetCurrentUserId() => _tenantProvider.GetCurrentUserId();

    public bool ShouldBypassTenantFilter() =>
        _tenantProvider.IsServiceCall() || _tenantProvider.IsAdmin();
}
