package com.erp.reconciliation.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.Builder;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 对账单实体
 * 记录每笔对账任务的核心信息
 * 
 * @author ERP Migration
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("reconciliation_bill")
public class ReconciliationBill {

    @TableId(type = IdType.AUTO)
    private Long id;

    /** 对账单号 */
    private String billNo;

    /** 对账批次号（同一批次对账的标识） */
    private String batchNo;

    /** 平台编码 */
    private String platform;

    /** 店铺ID */
    private Long shopId;

    /** 店铺名称 */
    private String shopName;

    /** 对账周期类型: daily-日对账, weekly-周对账, monthly-月对账 */
    private String periodType;

    /** 对账周期开始日期 */
    private LocalDateTime periodStart;

    /** 对账周期结束日期 */
    private LocalDateTime periodEnd;

    /** 平台账单总订单数 */
    private Integer platformOrderCount;

    /** 平台账单总金额 */
    private BigDecimal platformTotalAmount;

    /** 内部订单总数量 */
    private Integer internalOrderCount;

    /** 内部订单总金额 */
    private BigDecimal internalTotalAmount;

    /** 差异金额（平台-内部） */
    private BigDecimal differenceAmount;

    /** 匹配成功数量 */
    private Integer matchedCount;

    /** 匹配成功金额 */
    private BigDecimal matchedAmount;

    /** 差异订单数量 */
    private Integer differenceCount;

    /** 对账状态: pending-待对账, processing-对账中, completed-已完成, failed-对账失败 */
    private String reconciliationStatus;

    /** 对账结果: consistent-一致, inconsistent-有差异, partial-部分一致 */
    private String resultStatus;

    /** 对账开始时间 */
    private LocalDateTime reconciliationStartTime;

    /** 对账结束时间 */
    private LocalDateTime reconciliationEndTime;

    /** 确认时间 */
    private LocalDateTime confirmTime;

    /** 确认人ID */
    private Long confirmUserId;

    /** 确认人姓名 */
    private String confirmUserName;

    /** 备注 */
    private String remark;

    /** 租户ID */
    private Long tenantId;

    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createdAt;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;

    @TableLogic
    private LocalDateTime deletedAt;

    // ==================== 状态常量 ====================

    /** 对账状态 */
    public static final String STATUS_PENDING = "pending";
    public static final String STATUS_PROCESSING = "processing";
    public static final String STATUS_COMPLETED = "completed";
    public static final String STATUS_FAILED = "failed";

    /** 对账结果状态 */
    public static final String RESULT_CONSISTENT = "consistent";
    public static final String RESULT_INCONSISTENT = "inconsistent";
    public static final String RESULT_PARTIAL = "partial";

    /** 周期类型 */
    public static final String PERIOD_DAILY = "daily";
    public static final String PERIOD_WEEKLY = "weekly";
    public static final String PERIOD_MONTHLY = "monthly";
}
