using TakeoutSaaS.Domain.Tenants.Entities;
using TakeoutSaaS.Domain.Tenants.Enums;

namespace TakeoutSaaS.Domain.Tenants.Repositories;

/// <summary>
/// 租户配额使用仓储。
/// </summary>
public interface ITenantQuotaUsageRepository
{
    /// <summary>
    /// 获取租户指定配额的使用情况。
    /// </summary>
    /// <param name="tenantId">租户 ID（雪花算法）。</param>
    /// <param name="quotaType">配额类型。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>配额使用记录，未初始化则返回 null。</returns>
    Task<TenantQuotaUsage?> FindAsync(long tenantId, TenantQuotaType quotaType, CancellationToken cancellationToken = default);

    /// <summary>
    /// 按租户批量获取配额使用记录。
    /// </summary>
    /// <param name="tenantId">租户 ID（雪花算法）。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>该租户的所有配额使用记录。</returns>
    Task<IReadOnlyList<TenantQuotaUsage>> GetByTenantAsync(long tenantId, CancellationToken cancellationToken = default);

    /// <summary>
    /// 新增配额使用记录。
    /// </summary>
    /// <param name="usage">配额使用实体。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>异步任务。</returns>
    Task AddAsync(TenantQuotaUsage usage, CancellationToken cancellationToken = default);

    /// <summary>
    /// 更新配额使用记录。
    /// </summary>
    /// <param name="usage">配额使用实体。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>异步任务。</returns>
    Task UpdateAsync(TenantQuotaUsage usage, CancellationToken cancellationToken = default);

    /// <summary>
    /// 持久化。
    /// </summary>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>异步任务。</returns>
    Task SaveChangesAsync(CancellationToken cancellationToken = default);
}
