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_difference")
public class ReconciliationDifference {

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

    /** 对账单ID */
    private Long billId;

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

    /** 差异类型: amount_difference-金额差异, missing_platform-平台缺失, missing_internal-内部缺失, status_mismatch-状态不匹配 */
    private String differenceType;

    /** 平台订单号 */
    private String platformOrderSn;

    /** 内部订单ID */
    private Long internalOrderId;

    /** 内部订单号 */
    private String internalOrderSn;

    /** 平台订单金额 */
    private BigDecimal platformOrderAmount;

    /** 内部订单金额 */
    private BigDecimal internalOrderAmount;

    /** 差异金额 */
    private BigDecimal differenceAmount;

    /** 平台订单状态 */
    private String platformOrderStatus;

    /** 内部订单状态 */
    private String internalOrderStatus;

    /** 差异原因 */
    private String differenceReason;

    /** 处理状态: pending-待处理, investigating-调查中, resolved-已解决, write_off-已核销, write_back-已冲正 */
    private String handleStatus;

    /** 处理方式 */
    private String handleMethod;

    /** 处理人ID */
    private Long handleUserId;

    /** 处理人姓名 */
    private String handleUserName;

    /** 处理时间 */
    private LocalDateTime handleTime;

    /** 处理备注 */
    private String handleRemark;

    /** 关联对账单ID（用于追溯） */
    private Long relatedBillId;

    /** 备注 */
    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 TYPE_AMOUNT_DIFFERENCE = "amount_difference";
    
    /** 平台缺失（平台有但内部没有） */
    public static final String TYPE_MISSING_PLATFORM = "missing_platform";
    
    /** 内部缺失（内部有但平台没有） */
    public static final String TYPE_MISSING_INTERNAL = "missing_internal";
    
    /** 状态不匹配 */
    public static final String TYPE_STATUS_MISMATCH = "status_mismatch";

    // ==================== 处理状态常量 ====================

    /** 待处理 */
    public static final String HANDLE_PENDING = "pending";
    
    /** 调查中 */
    public static final String HANDLE_INVESTIGATING = "investigating";
    
    /** 已解决 */
    public static final String HANDLE_RESOLVED = "resolved";
    
    /** 已核销 */
    public static final String HANDLE_WRITE_OFF = "write_off";
    
    /** 已冲正 */
    public static final String HANDLE_WRITE_BACK = "write_back";
}
