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_inbound")
public class PurchaseInbound {

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

    /** 入库单号 */
    private String inboundNo;

    /** 采购单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 Integer acceptedQuantity;

    /** 残次品数量 */
    private Integer defectiveQuantity;

    /** 入库单总金额 */
    private BigDecimal totalAmount;

    /** 入库日期 */
    private LocalDateTime inboundTime;

    /** 期望到货时间 */
    private LocalDateTime expectedTime;

    /** 备注 */
    private String remark;

    /** 关联的仓库入库单号 */
    private String warehouseInboundNo;

    /** 操作人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<PurchaseInboundItem> items;

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class PurchaseInboundItem {
        private Long id;
        private Long inboundId;
        private String skuCode;
        private String skuName;
        private String unit;
        /** 计划数量（采购数量） */
        private Integer planQuantity;
        /** 实际到货数量 */
        private Integer arrivedQuantity;
        /** 验收合格数量 */
        private Integer acceptedQuantity;
        /** 残次品数量 */
        private Integer defectiveQuantity;
        /** 单价 */
        private BigDecimal price;
        /** 金额 */
        private BigDecimal amount;
        /** 备注 */
        private String remark;
    }
}
