package com.erp.purchase.dto;

import com.erp.purchase.entity.PurchaseOrder;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.Builder;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 * 采购订单DTO
 */
public class PurchaseOrderDTO {

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class CreateRequest {
        private String supplierCode;
        private Long supplierId;
        private Long warehouseId;
        private LocalDate orderDate;
        private LocalDate expectedDate;
        private BigDecimal taxRate;
        private String currency;
        private String paymentMethod;
        private String contact;
        private String phone;
        private String deliveryAddress;
        private String remark;

        @NotEmpty(message = "订单明细不能为空")
        private List<OrderItemRequest> items;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class OrderItemRequest {
        @NotNull(message = "SKU编码不能为空")
        private String skuCode;
        private String skuName;
        private String unit;
        @Positive(message = "单价必须大于0")
        private BigDecimal price;
        @Positive(message = "数量必须大于0")
        private Integer quantity;
        private String remark;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class UpdateRequest {
        private Long id;
        private Long supplierId;
        private Long warehouseId;
        private LocalDate expectedDate;
        private BigDecimal taxRate;
        private String paymentMethod;
        private String contact;
        private String phone;
        private String deliveryAddress;
        private String remark;
        private List<OrderItemRequest> items;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class ApproveRequest {
        private Long id;
        private String approveRemark;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class QueryRequest {
        private String orderNo;
        private Long supplierId;
        private String status;
        private LocalDate startDate;
        private LocalDate endDate;
        private int page = 1;
        private int limit = 20;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class VO {
        private Long id;
        private String orderNo;
        private Long supplierId;
        private String supplierName;
        private Long warehouseId;
        private String warehouseName;
        private LocalDate orderDate;
        private LocalDate expectedDate;
        private String status;
        private String statusDesc;
        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 String approveRemark;
        private java.time.LocalDateTime approveTime;
        private java.time.LocalDateTime createTime;
        private List<PurchaseOrder.PurchaseOrderItem> items;
    }
}
