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

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

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

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



    @NotEmpty(message = "订单号不能为空")
    private String orderNo;

    @Valid
    @NotNull(message = "采购订单抬头信息不能为空")
    private Head head;

    @Valid
    @NotNull(message = "采购订单抬头扩展信息不能为空")
    private Exte exte;

    @Valid
    @NotEmpty(message = "采购订单行项目列表不能为空")
    private List<Item> items;

    @Valid
    private List<Itex> itex; // 行项目扩展信息

    private JSONArray accts; // 科目分配信息(科目分配类别为K或P时使用)
    @Valid
    private List<Comp> comps; // 委托加工物料信息(委托加工订单时使用)

    @Schema(description = "采购订单抬头信息")
    @Data
    public static class Head {
        @Schema(description = "公司代码", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotEmpty(message = "公司代码不能为空")
        private String comp_code; // BUKRS CHAR4

        @Schema(description = "供应商帐号", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotEmpty(message = "供应商帐号不能为空")
        private String vendor; // LIFNR CHAR10

        @Schema(description = "采购凭证类型", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotEmpty(message = "采购凭证类型不能为空")
        private String doc_type; // BSART CHAR4

        @Schema(description = "采购凭证日期(YYYY-MM-DD)", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotNull(message = "采购凭证日期不能为空")
        private String doc_date; // BEDAT DATS8

        @Schema(description = "采购组织", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotEmpty(message = "采购组织不能为空")
        private String purch_org; // EKORG CHAR4

        @Schema(description = "采购组", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotEmpty(message = "采购组不能为空")
        private String pur_group; // EKGRP CHAR3

        @Schema(description = "货币码", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotEmpty(message = "货币码不能为空")
        private String currency; // WAERS CUKY5

        @Schema(description = "汇率(保留5位小数)")
        private BigDecimal exch_rate; // WKURS DEC9,5
    }

    @Schema(description = "采购订单抬头扩展信息")
    @Data
    public static class Exte {
        @Schema(description = "纸质合同号(已启用财务共享单位必填)", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotEmpty(message = "纸质合同号不能为空")
        private String zzhth; // CHAR60

        @Schema(description = "小协议号(绿星链通填入合同名称)")
        private String zxxyh; // CHAR60

        @Schema(description = "备注(绿星链通填入系统采购订单头号)")
        private String znote; // CHAR60

        @Schema(description = "代理方(使用客商编码)")
        private String zlifnr; // CHAR60
    }

    @Schema(description = "采购订单行项目信息")
    @Data
    public static class Item {
        @Schema(description = "行号", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotNull(message = "行号不能为空")
        private Integer po_item; // EBELP NUMC5

        @Schema(description = "物料号")
        private String material; // MATNR CHAR18

        @Schema(description = "工厂", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotEmpty(message = "工厂不能为空")
        private String plant; // WERKS CHAR4

        @Schema(description = "库存地点")
        private String stge_loc; // LGORT CHAR4

        @Schema(description = "数量(保留3位小数)", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotNull(message = "数量不能为空")
        private BigDecimal quantity; // MENGE QUAN13,3

        @Schema(description = "计量单位", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotEmpty(message = "计量单位不能为空")
        private String po_unit; // MEINS UNIT3

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

        @Schema(description = "价格单位(默认值1)")
        private Integer price_unit = 1; // PEINH DEC5

        @Schema(description = "税码")
        private String tax_code; // MWSKZ CHAR2

        @Schema(description = "基于GR的发票校验(Y/N)")
        private String gr_basediv; // WEBRE CHAR1（原字段名gr_basediv保持与源数据一致）

        @Schema(description = "允许无限制过量交货(Y/N)")
        private String unlimited_dlv; // UEBTK CHAR1

        @Schema(description = "批次")
        private String batch; // CHARG CHAR10

        @Schema(description = "项目类别(委托加工填L)")
        private String item_cat; // PSTYP CHAR1

        @Schema(description = "科目分配类别(A-固定资产/S-服务/K-成本中心/F-订单)")
        private String acctasscat; // KNTTP CHAR1

        @Schema(description = "物料组(服务采购必填)")
        private String matl_group; // MATKL CHAR9

        @Schema(description = "短文本(服务采购必填)")
        private String short_text; // TXZ01 CHAR40

        @Schema(description = "退货项目标识(X-是)")
        private String ret_item; // RETPO CHAR1

        @Schema(description = "免费项目标识(X-是)")
        private String free_item; // UMSON CHAR1

        @Schema(description = "外部行项目号(绿星链通必填)")
        private String vendrbatch; // LICHN CHAR15

        @Schema(description = "备注信息-需求单位")
        private String note_xq; // TDLINE CHAR132

        @Schema(description = "备注信息-物料详细")
        private String note_wl; // TDLINE CHAR132

        @Schema(description = "交货起止日期(格式:YYYYMMDD-YYYYMMDD)")
        private String vend_mat; // IDNLF CHAR22


    }

    @Schema(description = "行项目扩展信息")
    @Data
    public static class Itex {
        @Schema(description = "行号", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotNull(message = "行号不能为空")
        private Integer po_item;
        @Schema(description = "销售物料号(科目分配类别为S时必填)")
        private String zmatnr;

        @Schema(description = "统计型内部订单")
        private String zaufnr;

        @Schema(description = "采购类别(0-生产性物资类/1-项目投资类)")
        private String zpurty;

        @Schema(description = "原料湿重")
        private BigDecimal zmenge;
    }

//    @Schema(description = "行项目科目分配信息")
//    @Data
//    public static class Acct {
//        @Schema(description = "科目分配序号(从1开始)", requiredMode = Schema.RequiredMode.REQUIRED)
//        @NotNull(message = "科目分配序号不能为空")
//        private Integer serial_no; // DZEKKN NUMC2
//
//        @Schema(description = "总账科目编号")
//        private String gl_account; // SAKNR CHAR10
//
//        @Schema(description = "成本中心(科目分配类别为F时必填)")
//        private String costcenter; // KOSTL CHAR10（源数据为costcenter，保持一致）
//
//        @Schema(description = "订单号(科目分配类别为F时必填)")
//        private String orderid; // AUFNR CHAR12（源数据为orderid，保持一致）
//
//        @Schema(description = "主资产号(科目分配类别为A时必填)")
//        private String asset_no; // ANLN1 CHAR12
//
//        @Schema(description = "资产子编号(科目分配类别为A时必填，固定值'0')")
//        private String sub_number; // ANLN2 CHAR4
//    }

    @Schema(description = "委托加工物料信息")
    @Data
    public static class Comp {
        @Schema(description = "行号", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotNull(message = "行号不能为空")
        private Integer po_item;
        @Schema(description = "计划行号(从1开始)", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotNull(message = "计划行号不能为空")
        private Integer sched_line; // ETENR NUMC4

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

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

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

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

        @Schema(description = "组件计量单位(为空使用基本计量单位)")
        private String entry_uom; // MEINS UNIT3
    }
}
