using TakeoutSaaS.Domain.Tenants.Entities;
using TakeoutSaaS.Domain.Tenants.Enums;
namespace TakeoutSaaS.Domain.Tenants.Repositories;
///
/// 租户账单仓储。
///
public interface ITenantBillingRepository
{
///
/// 查询账单列表,按状态与时间范围筛选。
///
/// 租户 ID。
/// 账单状态。
/// 开始时间(UTC)。
/// 结束时间(UTC)。
/// 取消标记。
/// 账单集合。
Task> SearchAsync(
long tenantId,
TenantBillingStatus? status,
DateTime? from,
DateTime? to,
CancellationToken cancellationToken = default);
///
/// 按 ID 获取账单。
///
/// 租户 ID。
/// 账单 ID。
/// 取消标记。
/// 账单实体或 null。
Task FindByIdAsync(long tenantId, long billingId, CancellationToken cancellationToken = default);
///
/// 按账单编号获取账单。
///
/// 租户 ID。
/// 账单编号。
/// 取消标记。
/// 账单实体或 null。
Task FindByStatementNoAsync(long tenantId, string statementNo, CancellationToken cancellationToken = default);
///
/// 判断是否已存在指定周期开始时间的未取消账单(用于自动续费幂等)。
///
/// 租户 ID。
/// 账单周期开始时间(UTC)。
/// 取消标记。
/// 存在返回 true,否则 false。
Task ExistsNotCancelledByPeriodStartAsync(
long tenantId,
DateTime periodStart,
CancellationToken cancellationToken = default);
///
/// 新增账单。
///
/// 账单实体。
/// 取消标记。
/// 异步任务。
Task AddAsync(TenantBillingStatement bill, CancellationToken cancellationToken = default);
///
/// 更新账单。
///
/// 账单实体。
/// 取消标记。
/// 异步任务。
Task UpdateAsync(TenantBillingStatement bill, CancellationToken cancellationToken = default);
///
/// 保存变更。
///
/// 取消标记。
/// 异步任务。
Task SaveChangesAsync(CancellationToken cancellationToken = default);
///
/// 管理员端分页查询账单列表(跨租户)。
///
/// 租户 ID 筛选(可选)。
/// 账单状态筛选(可选)。
/// 开始时间(UTC,可选)。
/// 结束时间(UTC,可选)。
/// 关键词搜索(账单号或租户名)。
/// 页码(从 1 开始)。
/// 页大小。
/// 取消标记。
/// 账单集合与总数。
Task<(IReadOnlyList Items, int Total)> SearchPagedAsync(
long? tenantId,
TenantBillingStatus? status,
DateTime? from,
DateTime? to,
string? keyword,
int pageNumber,
int pageSize,
CancellationToken cancellationToken = default);
///
/// 按 ID 获取账单(不限租户,管理员端使用)。
///
/// 账单 ID。
/// 取消标记。
/// 账单实体或 null。
Task FindByIdAsync(long billingId, CancellationToken cancellationToken = default);
}