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.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 采购订单实体
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("purchase_order")
public class PurchaseOrder {

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

    /** 采购单号 */
    private String orderNo;

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

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

    /** 仓库ID（默认入库仓库） */
    private Long warehouseId;

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

    /** 订单日期 */
    private LocalDate orderDate;

    /** 预计到货日期 */
    private LocalDate expectedDate;

    /** 订单状态 */
    private String status;

    /** 订单总金额（未税） */
    private BigDecimal totalAmount;

    /** 税率 */
    private BigDecimal taxRate;

    /** 税额 */
    private BigDecimal taxAmount;

    /** 订单总金额（含税） */
    private BigDecimal totalWithTax;

    /** 已入库金额 */
    private BigDecimal inboundAmount;

    /** 已付款金额 */
    private BigDecimal paidAmount;

    /** 币种 */
    private String currency;

    /** 付款方式 */
    private String paymentMethod;

    /** 联系人 */
    private String contact;

    /** 联系电话 */
    private String phone;

    /** 收货地址 */
    private String deliveryAddress;

    /** 备注 */
    private String remark;

    /** 审批人 */
    private Long approverId;

    /** 审批时间 */
    private LocalDateTime approveTime;

    /** 审批备注 */
    private String approveRemark;

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

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class PurchaseOrderItem {
        private Long id;
        private String skuCode;
        private String skuName;
        private String unit;
        private BigDecimal price;
        private BigDecimal taxPrice;
        private Integer quantity;
        private Integer deliveredQuantity;
        private Integer returnedQuantity;
        private BigDecimal amount;
        private BigDecimal taxAmount;
        private BigDecimal amountWithTax;
        private String remark;
    }
}
