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

using OrderService.Infrastructure;

namespace OrderService.API.Infrastructure.Tenant;

/// <summary>
/// EN: Adapts the API-layer ITenantProvider to the Infrastructure IOrderTenantProvider interface.
///     This avoids circular dependency between API and Infrastructure layers.
/// VI: Chuyển đổi ITenantProvider tầng API sang interface IOrderTenantProvider tầng Infrastructure.
///     Điều này tránh dependency vòng giữa các lớp API và Infrastructure.
/// </summary>
public class OrderTenantProviderAdapter : IOrderTenantProvider
{
    private readonly ITenantProvider _tenantProvider;

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

    /// <inheritdoc />
    public Guid? GetCurrentShopId() => _tenantProvider.GetCurrentShopId();

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