using TakeoutSaaS.Domain.Tenants.Entities;

namespace TakeoutSaaS.Domain.Tenants.Services;

/// <summary>
/// 账单领域服务接口。
/// 负责处理账单生成、账单编号生成、逾期处理等跨实体的业务逻辑。
/// </summary>
public interface IBillingDomainService
{
    /// <summary>
    /// 根据订阅信息生成账单。
    /// </summary>
    /// <param name="subscription">租户订阅信息。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>生成的账单实体。</returns>
    Task<TenantBillingStatement> GenerateSubscriptionBillingAsync(
        TenantSubscription subscription,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 根据配额包购买信息生成账单。
    /// </summary>
    /// <param name="tenantId">租户 ID。</param>
    /// <param name="quotaPackage">配额包信息。</param>
    /// <param name="quantity">购买数量。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>生成的账单实体。</returns>
    Task<TenantBillingStatement> GenerateQuotaPurchaseBillingAsync(
        long tenantId,
        QuotaPackage quotaPackage,
        int quantity,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 生成唯一的账单编号。
    /// 格式示例：BIL-20251217-000001
    /// </summary>
    /// <returns>账单编号。</returns>
    string GenerateStatementNo();

    /// <summary>
    /// 处理逾期账单（批量标记逾期状态）。
    /// </summary>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>处理的账单数量。</returns>
    Task<int> ProcessOverdueBillingsAsync(CancellationToken cancellationToken = default);

    /// <summary>
    /// 计算账单总金额（含折扣和税费）。
    /// </summary>
    /// <param name="baseAmount">基础金额。</param>
    /// <param name="discountAmount">折扣金额。</param>
    /// <param name="taxAmount">税费金额。</param>
    /// <returns>总金额。</returns>
    decimal CalculateTotalAmount(decimal baseAmount, decimal discountAmount, decimal taxAmount);

    /// <summary>
    /// 验证账单状态是否可以进行支付操作。
    /// </summary>
    /// <param name="billing">账单实体。</param>
    /// <returns>是否可以支付。</returns>
    bool CanProcessPayment(TenantBillingStatement billing);
}
