package com.zt.plat.module.erp.controller.admin.erp.vo;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

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

/**
 * ERP采购订单保存请求VO
 */
@Data
@Schema(description = "ERP采购订单保存请求VO")
public class ErpOrderUpdateReqVO {


    // ====================== 1. 主结构字段 ======================
    @Schema(description = "采购订单号（EBELN）", requiredMode = Schema.RequiredMode.REQUIRED, example = "4500000001")
    @NotEmpty(message = "采购订单号不能为空")
    @ExcelProperty("采购订单号")
    private String poNumber;

    @Schema(description = "删除标识（ELOEK）", example = " ")
    @ExcelProperty("删除标识")
    private String deleteInd;

    @Schema(description = "货币码（WAERS）", requiredMode = Schema.RequiredMode.REQUIRED, example = "CNY")
    @NotEmpty(message = "货币码不能为空")
    @ExcelProperty("货币码")
    private String currency;

    @Schema(description = "汇率（WKURS），保留5位小数", requiredMode = Schema.RequiredMode.REQUIRED, example = "6.90000")
    @NotNull(message = "汇率不能为空")
    @ExcelProperty("汇率")
    private BigDecimal exchRate;

    // ====================== 2. 抬头扩展字段（结构-exte） ======================
    @Schema(description = "纸质合同号（zzhth），来源于合同台账接口，已启用财务共享单位必填", example = "HT202405001")
    @ExcelProperty("纸质合同号")
    private String zzhth;

    @Schema(description = "小协议号（zxxyh）", example = "XY202405001")
    @ExcelProperty("小协议号")
    private String zxxyh;

    @Schema(description = "备注（znote）", example = "月度常规采购")
    @ExcelProperty("备注")
    private String znote;

    @Schema(description = "代理方（zlifnr），使用客商编码", example = "D0010001")
    @ExcelProperty("代理方编码")
    private String zlifnr;

    // ====================== 3. 行项目字段（列表-item） ======================
    private List<item> items;


    // ====================== 4. 行项目扩展字段（列表-itex） ======================
    private List<itex> itexs;
    // ====================== 5. 科目分配字段（列表-acct，类别为K或P时使用） ======================
    private JSONArray accts;

    // ====================== 6. 委托加工物料字段（列表-comp，委托加工订单时使用） ======================
    private List<comp> comps;

    @Data
    @Schema(description = "ERP采购订单item更新请求VO")
    public static class item {
        @Schema(description = "行号（EBELP）", requiredMode = Schema.RequiredMode.REQUIRED, example = "00010")
        @NotEmpty(message = "行号不能为空")
        @ExcelProperty("行号")
        private Long po_item;

        @Schema(description = "物料号（MATNR）", example = "M0010001")
        @ExcelProperty("物料号")
        private String material;

        @Schema(description = "工厂（WERKS）", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001")
        @NotEmpty(message = "工厂不能为空")
        @ExcelProperty("工厂")
        private String plant;

        @Schema(description = "库存地点（LGORT）", example = "0001")
        @ExcelProperty("库存地点")
        private String stge_loc;

        @Schema(description = "数量（MENGE），保留3位小数", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.000")
        @NotNull(message = "数量不能为空")
        @ExcelProperty("数量")
        private String quantity;

        @Schema(description = "计量单位（MEINS），必须与该物料基本计量单位一致", requiredMode = Schema.RequiredMode.REQUIRED, example = "PC")
        @NotEmpty(message = "计量单位不能为空")
        @ExcelProperty("计量单位")
        private String po_unit;

        @Schema(description = "含税单价（NETPR），保留2位小数", requiredMode = Schema.RequiredMode.REQUIRED, example = "199.99")
        @NotNull(message = "含税单价不能为空")
        @ExcelProperty("含税单价")
        private BigDecimal net_price;

        @Schema(description = "价格单位（PEINH），固定值1", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
        @NotNull(message = "价格单位不能为空")
        @ExcelProperty("价格单位")
        private Integer price_unit;

        @Schema(description = "税码（MWSKZ）", example = "J1")
        @ExcelProperty("税码")
        private String tax_code;

        @Schema(description = "基于GR的发票校验（WEBRE）", example = "Y")
        @ExcelProperty("基于GR发票校验")
        private String gr_basediv;

        @Schema(description = "允许无限制过量交货（UEBTK）", example = "N")
        @ExcelProperty("允许过量交货")
        private String unlimited_dlv;

        @Schema(description = "批次（CHARG）", example = "B202405001")
        @ExcelProperty("批次")
        private String batch;

        @Schema(description = "项目类别（PSTYP），委托加工订单时填入L", example = "L")
        @ExcelProperty("项目类别")
        private String item_cat;

        @Schema(description = "科目分配类别（KNTTP），固定资产采购:A；服务采购:S-销售服务费/K-成本中心/F-订单", example = "K")
        @ExcelProperty("科目分配类别")
        private String acctasscat;

        @Schema(description = "物料组（MATKL），服务采购订单必填", example = "01")
        @ExcelProperty("物料组")
        private String matl_group;

        @Schema(description = "短文本（TXZ01），服务采购订单必填", example = "设备维修服务")
        @ExcelProperty("短文本")
        private String short_text;

        @Schema(description = "退货项目标识（RETPO），退货行项目填X", example = "X")
        @ExcelProperty("退货标识")
        private String ret_item;

        @Schema(description = "免费项目标识（UMSON），免费行项目填X", example = "X")
        @ExcelProperty("免费标识")
        private String free_item;

        @Schema(description = "外部行项目号（LICHN），绿星链通必填", example = "EXT0010")
        @ExcelProperty("外部行号")
        private String vendrbatch;

        @Schema(description = "备注信息-需求单位（TDLINE）", example = "生产一部")
        @ExcelProperty("需求单位备注")
        private String note_xq;

        @Schema(description = "备注信息-物料详细（TDLINE）", example = "304不锈钢，厚度2mm")
        @ExcelProperty("物料详细备注")
        private String note_wl;

        @Schema(description = "行项目删除标识（ELOEK）", example = "N")
        @ExcelProperty("行项目删除标识")
        private String delete_ind;
    }

    @Data
    public static class itex {
        @Schema(description = "行号（EBELP）", requiredMode = Schema.RequiredMode.REQUIRED, example = "00010")
        @NotEmpty(message = "行号不能为空")
        @ExcelProperty("行号")
        private Long po_item;
        @Schema(description = "销售物料号（zmatnr），科目分配类别为S时必填", example = "S0010001")
        @ExcelProperty("销售物料号")
        private BigDecimal zmatnr;

        @Schema(description = "统计型内部订单（zaufnr）", example = "OR0010001")
        @ExcelProperty("统计内部订单")
        private String zaufnr;

        @Schema(description = "采购类别（zpurty），0-生产性物资类；1-项目投资类", example = "0")
        @ExcelProperty("采购类别")
        private String zpurty;

        @Schema(description = "原料湿重（zmenge）", example = "105.500")
        @ExcelProperty("原料湿重")
        private BigDecimal zmenge;

    }
//
//    @Data
//    public static class acct {
//        @Schema(description = "行号（EBELP）", requiredMode = Schema.RequiredMode.REQUIRED, example = "00010")
//        @NotEmpty(message = "行号不能为空")
//        @ExcelProperty("行号")
//        private String poItem;
//        @Schema(description = "科目分配的序号（DZEKKN），从1开始编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
//        @NotNull(message = "科目分配序号不能为空")
//        @ExcelProperty("科目分配序号")
//        private Integer serialNo;
//
//        @Schema(description = "总账科目编号（SAKNR）", example = "1001010000")
//        @ExcelProperty("总账科目")
//        private String glAccount;
//
//        @Schema(description = "成本中心（KOSTL），科目分配类别为K或F时必填", example = "C0010001")
//        @ExcelProperty("成本中心")
//        private String costcenter;
//
//        @Schema(description = "订单号（AUFNR），科目分配类别为F时必填", example = "OR0010001")
//        @ExcelProperty("订单号")
//        private String orderid;
//
//        @Schema(description = "主资产号（ANLN1），科目分配类别为A时必填", example = "AS0010001")
//        @ExcelProperty("主资产号")
//        private String assetNo;
//
//        @Schema(description = "资产子编号（ANLN2），科目分配类别为A时必填，固定值‘0’", example = "0")
//        @ExcelProperty("资产子编号")
//        private String subNumber;
//    }

//    @Data
//    public static class comp {
//        @Schema(description = "行号（EBELP）", requiredMode = Schema.RequiredMode.REQUIRED, example = "00010")
//        @NotEmpty(message = "行号不能为空")
//        @ExcelProperty("行号")
//        private Long po_item;
//
//        @Schema(description = "计划行号（ETENR），从1开始编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
//        @NotNull(message = "计划行号不能为空")
//        @ExcelProperty("计划行号")
//        private Integer sched_line;
//
//        @Schema(description = "项目编号（RSPOS），从1开始编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
//        @NotNull(message = "项目编号不能为空")
//        @ExcelProperty("项目编号")
//        private Integer item_no;
//
//        @Schema(description = "加工前物料号（MATNR）", requiredMode = Schema.RequiredMode.REQUIRED, example = "M0020001")
//        @NotEmpty(message = "加工前物料号不能为空")
//        @ExcelProperty("加工前物料号")
//        private String material;
//
//        @Schema(description = "委托加工发货工厂（PLANT）", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001")
//        @NotEmpty(message = "委托加工发货工厂不能为空")
//        @ExcelProperty("委托发货工厂")
//        private String plant;
//
//        @Schema(description = "委托加工需求数量（MENGE），保留3位小数", requiredMode = Schema.RequiredMode.REQUIRED, example = "95.000")
//        @NotNull(message = "委托加工需求数量不能为空")
//        @ExcelProperty("委托需求数量")
//        private BigDecimal entry_quantity;
//
//        @Schema(description = "组件计量单位（MEINS），为空使用基本计量单位", example = "PC")
//        @ExcelProperty("组件计量单位")
//        private String entry_uom;
//    }


    @Data
    @Schema(description = "委托加工物料comp更新请求VO") // 补充Schema注解（可选，规范）
    public static class comp {
        @Schema(description = "行号（EBELP）", requiredMode = Schema.RequiredMode.REQUIRED, example = "00010")
        @NotNull(message = "行号不能为空") // 修正：Long类型用@NotNull，而非@NotEmpty
        @ExcelProperty("行号")
        private Long po_item;

        @Schema(description = "计划行号（ETENR），从1开始编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
        @NotNull(message = "计划行号不能为空")
        @ExcelProperty("计划行号")
        private Integer sched_line;

        @Schema(description = "项目编号（RSPOS），从1开始编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
        @NotNull(message = "项目编号不能为空")
        @ExcelProperty("项目编号")
        private Integer item_no;

        @Schema(description = "加工前物料号（MATNR）", requiredMode = Schema.RequiredMode.REQUIRED, example = "M0020001")
        @NotEmpty(message = "加工前物料号不能为空")
        @ExcelProperty("加工前物料号")
        private String material;

        @Schema(description = "委托加工发货工厂（PLANT）", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001")
        @NotEmpty(message = "委托加工发货工厂不能为空")
        @ExcelProperty("委托发货工厂")
        private String plant;

        @Schema(description = "委托加工需求数量（MENGE），保留3位小数", requiredMode = Schema.RequiredMode.REQUIRED, example = "95.000")
        @NotNull(message = "委托加工需求数量不能为空")
        @ExcelProperty("委托需求数量")
        private BigDecimal entry_quantity;

        @Schema(description = "组件计量单位（MEINS），为空使用基本计量单位", example = "PC")
        @ExcelProperty("组件计量单位")
        private String entry_uom;
    }
}
