package com.erp.purchase.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("purchase_return")
public class PurchaseReturn {

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

    /** 退货单号 */
    private String returnNo;

    /** 关联采购单ID */
    private Long purchaseOrderId;

    /** 关联采购单号 */
    private String purchaseOrderNo;

    /** 供应商ID */
    private Long supplierId;

    /** 供应商名称 */
    private String supplierName;

    /** 仓库ID */
    private Long warehouseId;

    /** 仓库名称 */
    private String warehouseName;

    /** 退货状态 */
    private String status;

    /** 退货总数量 */
    private Integer totalQuantity;

    /** 退货总金额 */
    private BigDecimal totalAmount;

    /** 退款金额（已退） */
    private BigDecimal refundedAmount;

    /** 退货原因 */
    private String returnReason;

    /** 退货类型：quality=质量问题, wrong=发错货, other=其他 */
    private String returnType;

    /** 出库时间 */
    private LocalDateTime outboundTime;

    /** 备注 */
    private String remark;

    /** 关联的仓库出库单号 */
    private String warehouseOutboundNo;

    /** 操作人ID */
    private Long operatorId;

    /** 操作人名称 */
    private String operatorName;

    /** 租户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;

    // ===== 非持久化字段 =====

    /** 退货明细 */
    private java.util.List<PurchaseReturnItem> items;

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class PurchaseReturnItem {
        private Long id;
        private Long returnId;
        private String skuCode;
        private String skuName;
        private String unit;
        /** 原采购数量 */
        private Integer purchaseQuantity;
        /** 退货数量 */
        private Integer returnQuantity;
        /** 单价 */
        private BigDecimal price;
        /** 金额 */
        private BigDecimal amount;
        /** 备注 */
        private String remark;
    }
}
