package com.erp.finance.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;

/**
 * 退款记录 - 订单退款或售后退款时生成
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("fin_refund_record")
public class RefundRecord {

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

    /** 退款单号 */
    private String refundNo;

    /** 关联订单号 */
    private String orderNo;

    /** 平台短ID */
    private String shortId;

    /** 退款金额 */
    private BigDecimal refundAmount;

    /** 退款原因 */
    private String refundReason;

    /** 退款时间 */
    private LocalDateTime refundTime;

    /** 原收款记录ID */
    private Long incomeRecordId;

    /** 原收款金额 */
    private BigDecimal originalAmount;

    /** 退款方式: original/other */
    private String refundMethod;

    /** 退款账户信息 */
    private String refundAccount;

    /** 退款状态: pending/processing/completed/failed */
    private String status;

    /** 退款类型: order_refund/aftersale_refund */
    private String type;

    /** 来源ID（如售后单ID） */
    private Long sourceId;

    /** 来源: order/aftersale */
    private String source;

    /** 财务退款处理人 */
    private String operator;

    /** 完成时间 */
    private LocalDateTime completeTime;

    /** 失败原因 */
    private String failReason;

    /** 外部退款流水号 */
    private String externalRefundNo;

    /** 备注 */
    private String remark;

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

    /** 创建人 */
    private Long createBy;

    /** 创建时间 */
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    /** 更新人 */
    private Long updateBy;

    /** 更新时间 */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    /** 逻辑删除 */
    @TableLogic
    private Integer deleted;

    // ============== 常量 ==============
    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 TYPE_ORDER_REFUND = "order_refund";
    public static final String TYPE_AFTERSALE_REFUND = "aftersale_refund";

    public static final String SOURCE_ORDER = "order";
    public static final String SOURCE_AFTERSALE = "aftersale";
}
