namespace TakeoutSaaS.TenantApi.Contracts.Finance;

/// <summary>
/// 交易流水筛选请求。
/// </summary>
public class FinanceTransactionFilterRequest
{
    /// <summary>
    /// 门店 ID。
    /// </summary>
    public string StoreId { get; set; } = string.Empty;

    /// <summary>
    /// 开始日期（yyyy-MM-dd）。
    /// </summary>
    public string? StartDate { get; set; }

    /// <summary>
    /// 结束日期（yyyy-MM-dd）。
    /// </summary>
    public string? EndDate { get; set; }

    /// <summary>
    /// 交易类型（income/refund/stored_card_recharge/point_redeem）。
    /// </summary>
    public string? Type { get; set; }

    /// <summary>
    /// 渠道（delivery/pickup/dine_in）。
    /// </summary>
    public string? Channel { get; set; }

    /// <summary>
    /// 支付方式（wechat/alipay/cash/card/balance）。
    /// </summary>
    public string? PaymentMethod { get; set; }

    /// <summary>
    /// 关键词（流水号/订单号）。
    /// </summary>
    public string? Keyword { get; set; }
}

/// <summary>
/// 交易流水列表请求。
/// </summary>
public sealed class FinanceTransactionListRequest : FinanceTransactionFilterRequest
{
    /// <summary>
    /// 页码。
    /// </summary>
    public int Page { get; set; } = 1;

    /// <summary>
    /// 每页条数。
    /// </summary>
    public int PageSize { get; set; } = 20;
}

/// <summary>
/// 交易流水详情请求。
/// </summary>
public sealed class FinanceTransactionDetailRequest
{
    /// <summary>
    /// 门店 ID。
    /// </summary>
    public string StoreId { get; set; } = string.Empty;

    /// <summary>
    /// 交易标识（sourceType:sourceId）。
    /// </summary>
    public string TransactionId { get; set; } = string.Empty;
}

/// <summary>
/// 交易流水列表结果。
/// </summary>
public sealed class FinanceTransactionListResultResponse
{
    /// <summary>
    /// 列表。
    /// </summary>
    public List<FinanceTransactionListItemResponse> Items { get; set; } = [];

    /// <summary>
    /// 总数。
    /// </summary>
    public int Total { get; set; }

    /// <summary>
    /// 页码。
    /// </summary>
    public int Page { get; set; }

    /// <summary>
    /// 每页条数。
    /// </summary>
    public int PageSize { get; set; }

    /// <summary>
    /// 本页收入。
    /// </summary>
    public decimal PageIncomeAmount { get; set; }

    /// <summary>
    /// 本页退款。
    /// </summary>
    public decimal PageRefundAmount { get; set; }
}

/// <summary>
/// 交易流水行。
/// </summary>
public sealed class FinanceTransactionListItemResponse
{
    /// <summary>
    /// 交易标识。
    /// </summary>
    public string TransactionId { get; set; } = string.Empty;

    /// <summary>
    /// 流水号。
    /// </summary>
    public string TransactionNo { get; set; } = string.Empty;

    /// <summary>
    /// 关联订单号。
    /// </summary>
    public string? OrderNo { get; set; }

    /// <summary>
    /// 类型编码。
    /// </summary>
    public string Type { get; set; } = string.Empty;

    /// <summary>
    /// 类型文案。
    /// </summary>
    public string TypeText { get; set; } = string.Empty;

    /// <summary>
    /// 渠道文案。
    /// </summary>
    public string Channel { get; set; } = string.Empty;

    /// <summary>
    /// 支付方式文案。
    /// </summary>
    public string PaymentMethod { get; set; } = string.Empty;

    /// <summary>
    /// 交易金额。
    /// </summary>
    public decimal Amount { get; set; }

    /// <summary>
    /// 交易时间。
    /// </summary>
    public string OccurredAt { get; set; } = string.Empty;

    /// <summary>
    /// 备注。
    /// </summary>
    public string Remark { get; set; } = string.Empty;

    /// <summary>
    /// 是否收入。
    /// </summary>
    public bool IsIncome { get; set; }
}

/// <summary>
/// 交易流水统计结果。
/// </summary>
public sealed class FinanceTransactionStatsResponse
{
    /// <summary>
    /// 总收入。
    /// </summary>
    public decimal TotalIncome { get; set; }

    /// <summary>
    /// 总退款。
    /// </summary>
    public decimal TotalRefund { get; set; }

    /// <summary>
    /// 总笔数。
    /// </summary>
    public int TotalCount { get; set; }
}

/// <summary>
/// 交易流水详情。
/// </summary>
public sealed class FinanceTransactionDetailResponse
{
    /// <summary>
    /// 交易标识。
    /// </summary>
    public string TransactionId { get; set; } = string.Empty;

    /// <summary>
    /// 流水号。
    /// </summary>
    public string TransactionNo { get; set; } = string.Empty;

    /// <summary>
    /// 类型编码。
    /// </summary>
    public string Type { get; set; } = string.Empty;

    /// <summary>
    /// 类型文案。
    /// </summary>
    public string TypeText { get; set; } = string.Empty;

    /// <summary>
    /// 门店 ID。
    /// </summary>
    public string StoreId { get; set; } = string.Empty;

    /// <summary>
    /// 关联订单号。
    /// </summary>
    public string? OrderNo { get; set; }

    /// <summary>
    /// 渠道文案。
    /// </summary>
    public string Channel { get; set; } = string.Empty;

    /// <summary>
    /// 支付方式文案。
    /// </summary>
    public string PaymentMethod { get; set; } = string.Empty;

    /// <summary>
    /// 交易金额。
    /// </summary>
    public decimal Amount { get; set; }

    /// <summary>
    /// 交易时间。
    /// </summary>
    public string OccurredAt { get; set; } = string.Empty;

    /// <summary>
    /// 备注。
    /// </summary>
    public string Remark { get; set; } = string.Empty;

    /// <summary>
    /// 顾客姓名。
    /// </summary>
    public string CustomerName { get; set; } = string.Empty;

    /// <summary>
    /// 顾客手机号。
    /// </summary>
    public string CustomerPhone { get; set; } = string.Empty;

    /// <summary>
    /// 退款单号。
    /// </summary>
    public string? RefundNo { get; set; }

    /// <summary>
    /// 退款原因。
    /// </summary>
    public string? RefundReason { get; set; }

    /// <summary>
    /// 会员名称。
    /// </summary>
    public string? MemberName { get; set; }

    /// <summary>
    /// 会员手机号。
    /// </summary>
    public string? MemberMobileMasked { get; set; }

    /// <summary>
    /// 充值金额。
    /// </summary>
    public decimal? RechargeAmount { get; set; }

    /// <summary>
    /// 赠送金额。
    /// </summary>
    public decimal? GiftAmount { get; set; }

    /// <summary>
    /// 到账金额。
    /// </summary>
    public decimal? ArrivedAmount { get; set; }

    /// <summary>
    /// 积分变动值。
    /// </summary>
    public int? PointChangeAmount { get; set; }

    /// <summary>
    /// 积分变动后余额。
    /// </summary>
    public int? PointBalanceAfterChange { get; set; }
}

/// <summary>
/// 交易流水导出结果。
/// </summary>
public sealed class FinanceTransactionExportResponse
{
    /// <summary>
    /// 文件名。
    /// </summary>
    public string FileName { get; set; } = string.Empty;

    /// <summary>
    /// 文件内容（Base64）。
    /// </summary>
    public string FileContentBase64 { get; set; } = string.Empty;

    /// <summary>
    /// 导出总数。
    /// </summary>
    public int TotalCount { get; set; }
}
