package com.erp.invoice.dto;

import lombok.Data;

import jakarta.validation.constraints.*;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 * 发票申请/创建请求DTO
 */
@Data
public class InvoiceRequest {
    
    // ==================== 发票类型 ====================
    
    @NotNull(message = "发票类型不能为空")
    @Min(value = 1, message = "发票类型不合法")
    @Max(value = 4, message = "发票类型不合法")
    private Integer invoiceType;
    
    // ==================== 购方信息 ====================
    
    @NotBlank(message = "购方名称不能为空")
    @Size(max = 200, message = "购方名称长度不能超过200")
    private String buyerName;
    
    @NotBlank(message = "购方纳税人识别号不能为空")
    @Size(max = 50, message = "购方纳税人识别号长度不能超过50")
    private String buyerTaxNo;
    
    @Size(max = 200, message = "购方地址电话长度不能超过200")
    private String buyerAddressPhone;
    
    @Size(max = 100, message = "购方银行账号长度不能超过100")
    private String buyerBankAccount;
    
    // ==================== 金额信息 ====================
    
    @NotNull(message = "价税合计金额不能为空")
    @DecimalMin(value = "0.01", message = "价税合计金额必须大于0")
    private BigDecimal totalAmount;
    
    @NotNull(message = "不含税金额不能为空")
    @DecimalMin(value = "0.01", message = "不含税金额必须大于0")
    private BigDecimal amount;
    
    @NotNull(message = "税额不能为空")
    @DecimalMin(value = "0", message = "税额不能为负")
    private BigDecimal taxAmount;
    
    @NotNull(message = "税率不能为空")
    @DecimalMin(value = "0", message = "税率不能为负")
    @DecimalMax(value = "1", message = "税率不能超过1")
    private BigDecimal taxRate;
    
    // ==================== 关联信息 ====================
    
    private Long orderId;
    
    private String orderNo;
    
    private Long customerId;
    
    private String customerName;
    
    // ==================== 发票内容 ====================
    
    @Size(max = 500, message = "发票内容长度不能超过500")
    private String invoiceContent;
    
    // ==================== 备注 ====================
    
    @Size(max = 500, message = "备注长度不能超过500")
    private String remark;
    
    // ==================== 发票明细 ====================
    
    private List<InvoiceItemRequest> items;
    
    /**
     * 发票明细项
     */
    @Data
    public static class InvoiceItemRequest {
        
        @NotBlank(message = "商品名称不能为空")
        @Size(max = 200, message = "商品名称长度不能超过200")
        private String goodsName;
        
        @Size(max = 100, message = "规格型号长度不能超过100")
        private String spec;
        
        @Size(max = 20, message = "单位长度不能超过20")
        private String unit;
        
        @DecimalMin(value = "0.01", message = "数量必须大于0")
        private BigDecimal quantity;
        
        private BigDecimal unitPrice;
        
        private BigDecimal amount;
        
        private BigDecimal taxRate;
        
        private BigDecimal taxAmount;
        
        private BigDecimal totalAmount;
        
        @Size(max = 50, message = "商品编码长度不能超过50")
        private String goodsCode;
        
        @Size(max = 50, message = "税收分类编码长度不能超过50")
        private String taxClassificationCode;
        
        private Integer preferentialFlag;
        
        private Integer zeroTaxFlag;
    }
}
