using TakeoutSaaS.Domain.Finance.Enums;
using TakeoutSaaS.Domain.Finance.Models;
using TakeoutSaaS.Domain.Orders.Enums;
using TakeoutSaaS.Domain.Payments.Enums;

namespace TakeoutSaaS.Domain.Finance.Repositories;

/// <summary>
/// 财务交易流水仓储契约。
/// </summary>
public interface IFinanceTransactionRepository
{
    /// <summary>
    /// 查询交易流水分页。
    /// </summary>
    Task<FinanceTransactionPageSnapshot> SearchPageAsync(
        long tenantId,
        long storeId,
        DateTime? startAt,
        DateTime? endAt,
        FinanceTransactionType? transactionType,
        DeliveryType? deliveryType,
        PaymentMethod? paymentMethod,
        string? keyword,
        int page,
        int pageSize,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 查询交易流水统计。
    /// </summary>
    Task<FinanceTransactionStatsSnapshot> GetStatsAsync(
        long tenantId,
        long storeId,
        DateTime? startAt,
        DateTime? endAt,
        FinanceTransactionType? transactionType,
        DeliveryType? deliveryType,
        PaymentMethod? paymentMethod,
        string? keyword,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 查询交易流水详情。
    /// </summary>
    Task<FinanceTransactionRecord?> GetDetailAsync(
        long tenantId,
        long storeId,
        FinanceTransactionSourceType sourceType,
        long sourceId,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 查询导出数据。
    /// </summary>
    Task<IReadOnlyList<FinanceTransactionRecord>> ListForExportAsync(
        long tenantId,
        long storeId,
        DateTime? startAt,
        DateTime? endAt,
        FinanceTransactionType? transactionType,
        DeliveryType? deliveryType,
        PaymentMethod? paymentMethod,
        string? keyword,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 查询到账概览统计。
    /// </summary>
    Task<FinanceSettlementStatsSnapshot> GetSettlementStatsAsync(
        long tenantId,
        long storeId,
        DateTime currentUtc,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 查询到账账户信息。
    /// </summary>
    Task<FinanceSettlementAccountSnapshot?> GetSettlementAccountAsync(
        long tenantId,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 查询到账汇总分页。
    /// </summary>
    Task<FinanceSettlementPageSnapshot> SearchSettlementPageAsync(
        long tenantId,
        long storeId,
        DateTime? startAt,
        DateTime? endAt,
        PaymentMethod? paymentMethod,
        int page,
        int pageSize,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 查询到账明细。
    /// </summary>
    Task<IReadOnlyList<FinanceSettlementDetailItemSnapshot>> GetSettlementDetailsAsync(
        long tenantId,
        long storeId,
        DateTime arrivedDate,
        PaymentMethod paymentMethod,
        int take,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 查询到账导出数据。
    /// </summary>
    Task<IReadOnlyList<FinanceSettlementListItemSnapshot>> ListSettlementForExportAsync(
        long tenantId,
        long storeId,
        DateTime? startAt,
        DateTime? endAt,
        PaymentMethod? paymentMethod,
        CancellationToken cancellationToken = default);
}
