using System.Text.Json.Serialization;
using TakeoutSaaS.Domain.Tenants.Enums;
using TakeoutSaaS.Shared.Abstractions.Serialization;
namespace TakeoutSaaS.Application.App.Billings.Dto.Legacy;
///
/// 账单列表 DTO(用于列表展示)。
///
public sealed record BillingListDto
{
///
/// 账单 ID(雪花算法,序列化为字符串)。
///
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
public long Id { get; init; }
///
/// 租户 ID(雪花算法,序列化为字符串)。
///
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
public long TenantId { get; init; }
///
/// 租户名称。
///
public string TenantName { get; init; } = string.Empty;
///
/// 关联订阅 ID(仅订阅/续费账单可能有值)。
///
[JsonConverter(typeof(NullableSnowflakeIdJsonConverter))]
public long? SubscriptionId { get; init; }
///
/// 账单编号。
///
public string StatementNo { get; init; } = string.Empty;
///
/// 账单类型。
///
public BillingType BillingType { get; init; }
///
/// 计费周期开始时间(UTC)。
///
public DateTime PeriodStart { get; init; }
///
/// 计费周期结束时间(UTC)。
///
public DateTime PeriodEnd { get; init; }
///
/// 应付金额。
///
public decimal AmountDue { get; init; }
///
/// 折扣金额。
///
public decimal DiscountAmount { get; init; }
///
/// 税费金额。
///
public decimal TaxAmount { get; init; }
///
/// 总金额(应付金额 - 折扣 + 税费)。
///
public decimal TotalAmount { get; init; }
///
/// 已付金额。
///
public decimal AmountPaid { get; init; }
///
/// 币种。
///
public string Currency { get; init; } = "CNY";
///
/// 账单状态。
///
public TenantBillingStatus Status { get; init; }
///
/// 到期日(UTC)。
///
public DateTime DueDate { get; init; }
///
/// 是否已逾期(根据到期日与状态综合判断)。
///
public bool IsOverdue { get; init; }
///
/// 逾期天数(未逾期为 0)。
///
public int OverdueDays { get; init; }
///
/// 创建时间(UTC)。
///
public DateTime CreatedAt { get; init; }
///
/// 更新时间(UTC)。
///
public DateTime? UpdatedAt { get; init; }
}
///
/// 账单详情 DTO(含明细项)。
///
public sealed record BillingDetailDto
{
///
/// 账单 ID(雪花算法,序列化为字符串)。
///
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
public long Id { get; init; }
///
/// 租户 ID(雪花算法,序列化为字符串)。
///
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
public long TenantId { get; init; }
///
/// 租户名称。
///
public string TenantName { get; init; } = string.Empty;
///
/// 账单编号。
///
public string StatementNo { get; init; } = string.Empty;
///
/// 关联订阅 ID(仅订阅/续费账单可能有值)。
///
[JsonConverter(typeof(NullableSnowflakeIdJsonConverter))]
public long? SubscriptionId { get; init; }
///
/// 账单类型。
///
public BillingType BillingType { get; init; }
///
/// 计费周期开始时间(UTC)。
///
public DateTime PeriodStart { get; init; }
///
/// 计费周期结束时间(UTC)。
///
public DateTime PeriodEnd { get; init; }
///
/// 应付金额。
///
public decimal AmountDue { get; init; }
///
/// 折扣金额。
///
public decimal DiscountAmount { get; init; }
///
/// 税费金额。
///
public decimal TaxAmount { get; init; }
///
/// 总金额(应付金额 - 折扣 + 税费)。
///
public decimal TotalAmount { get; init; }
///
/// 已付金额。
///
public decimal AmountPaid { get; init; }
///
/// 币种。
///
public string Currency { get; init; } = "CNY";
///
/// 账单状态。
///
public TenantBillingStatus Status { get; init; }
///
/// 到期日(UTC)。
///
public DateTime DueDate { get; init; }
///
/// 账单明细 JSON。
///
public string? LineItemsJson { get; init; }
///
/// 账单明细列表(从 JSON 反序列化)。
///
public IReadOnlyList LineItems { get; init; } = [];
///
/// 支付记录列表。
///
public IReadOnlyList Payments { get; init; } = [];
///
/// 备注信息。
///
public string? Notes { get; init; }
///
/// 创建时间(UTC)。
///
public DateTime CreatedAt { get; init; }
///
/// 更新时间(UTC)。
///
public DateTime? UpdatedAt { get; init; }
}
///
/// 账单明细项 DTO。
///
public sealed record BillingLineItemDto
{
///
/// 明细类型(如:套餐费、配额包费用、其他费用)。
///
public string ItemType { get; init; } = string.Empty;
///
/// 描述。
///
public string Description { get; init; } = string.Empty;
///
/// 数量。
///
public decimal Quantity { get; init; }
///
/// 单价。
///
public decimal UnitPrice { get; init; }
///
/// 金额(数量 × 单价)。
///
public decimal Amount { get; init; }
///
/// 折扣率(0-1)。
///
public decimal? DiscountRate { get; init; }
}
///
/// 支付记录 DTO。
///
public sealed record PaymentRecordDto
{
///
/// 支付记录 ID(雪花算法,序列化为字符串)。
///
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
public long Id { get; init; }
///
/// 租户 ID(雪花算法,序列化为字符串)。
///
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
public long TenantId { get; init; }
///
/// 账单 ID(雪花算法,序列化为字符串)。
///
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
public long BillingId { get; init; }
///
/// 支付金额。
///
public decimal Amount { get; init; }
///
/// 支付方式。
///
public TenantPaymentMethod Method { get; init; }
///
/// 支付状态。
///
public TenantPaymentStatus Status { get; init; }
///
/// 支付流水号。
///
public string? TransactionNo { get; init; }
///
/// 支付凭证 URL。
///
public string? ProofUrl { get; init; }
///
/// 备注。
///
public string? Notes { get; init; }
///
/// 审核状态(待审核/已通过/已拒绝)。
///
public bool IsVerified { get; init; }
///
/// 审核人 ID(雪花算法,序列化为字符串)。
///
[JsonConverter(typeof(NullableSnowflakeIdJsonConverter))]
public long? VerifiedBy { get; init; }
///
/// 审核时间(UTC)。
///
public DateTime? VerifiedAt { get; init; }
///
/// 退款原因。
///
public string? RefundReason { get; init; }
///
/// 退款时间(UTC)。
///
public DateTime? RefundedAt { get; init; }
///
/// 支付时间(UTC)。
///
public DateTime? PaidAt { get; init; }
///
/// 创建时间(UTC)。
///
public DateTime CreatedAt { get; init; }
}
///
/// 账单统计 DTO。
///
public sealed record BillingStatisticsDto
{
///
/// 租户 ID(当前租户)。
///
[JsonConverter(typeof(NullableSnowflakeIdJsonConverter))]
public long? TenantId { get; init; }
///
/// 统计周期开始时间(UTC)。
///
public DateTime StartDate { get; init; }
///
/// 统计周期结束时间(UTC)。
///
public DateTime EndDate { get; init; }
///
/// 分组方式(Day/Week/Month)。
///
public string GroupBy { get; init; } = "Day";
///
/// 总账单数量。
///
public int TotalCount { get; init; }
///
/// 待付款账单数量。
///
public int PendingCount { get; init; }
///
/// 已付款账单数量。
///
public int PaidCount { get; init; }
///
/// 逾期账单数量。
///
public int OverdueCount { get; init; }
///
/// 已取消账单数量。
///
public int CancelledCount { get; init; }
///
/// 总应收金额(账单原始应付)。
///
public decimal TotalAmountDue { get; init; }
///
/// 总实收金额。
///
public decimal TotalAmountPaid { get; init; }
///
/// 总未收金额(总金额 - 实收)。
///
public decimal TotalAmountUnpaid { get; init; }
///
/// 逾期未收金额。
///
public decimal TotalOverdueAmount { get; init; }
///
/// 分组统计:应收金额趋势(Key 为分组起始日期 yyyy-MM-dd)。
///
public Dictionary AmountDueTrend { get; init; } = [];
///
/// 分组统计:实收金额趋势(Key 为分组起始日期 yyyy-MM-dd)。
///
public Dictionary AmountPaidTrend { get; init; } = [];
///
/// 分组统计:账单数量趋势(Key 为分组起始日期 yyyy-MM-dd)。
///
public Dictionary CountTrend { get; init; } = [];
}
///
/// 账单导出 DTO。
///
public sealed record BillingExportDto
{
///
/// 账单 ID(雪花算法,序列化为字符串)。
///
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
public long Id { get; init; }
///
/// 租户 ID(雪花算法,序列化为字符串)。
///
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
public long TenantId { get; init; }
///
/// 租户名称。
///
public string TenantName { get; init; } = string.Empty;
///
/// 账单编号。
///
public string StatementNo { get; init; } = string.Empty;
///
/// 关联订阅 ID(仅订阅/续费账单可能有值)。
///
[JsonConverter(typeof(NullableSnowflakeIdJsonConverter))]
public long? SubscriptionId { get; init; }
///
/// 账单类型。
///
public BillingType BillingType { get; init; }
///
/// 计费周期开始时间(UTC)。
///
public DateTime PeriodStart { get; init; }
///
/// 计费周期结束时间(UTC)。
///
public DateTime PeriodEnd { get; init; }
///
/// 应付金额。
///
public decimal AmountDue { get; init; }
///
/// 折扣金额。
///
public decimal DiscountAmount { get; init; }
///
/// 税费金额。
///
public decimal TaxAmount { get; init; }
///
/// 总金额。
///
public decimal TotalAmount { get; init; }
///
/// 已付金额。
///
public decimal AmountPaid { get; init; }
///
/// 账单状态。
///
public TenantBillingStatus Status { get; init; }
///
/// 币种。
///
public string Currency { get; init; } = "CNY";
///
/// 到期日(UTC)。
///
public DateTime DueDate { get; init; }
///
/// 备注信息。
///
public string? Notes { get; init; }
///
/// 账单明细列表。
///
public List LineItems { get; init; } = [];
}