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

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

/**
 * ERP销售订单保存请求VO
 */
@Data
@Schema(description = "ERP销售订单保存请求参数")
public class ErpSalesOrderSaveReqVO {
    @Schema(description = "订单号", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotEmpty(message = "订单号")
    private String orderNo;

    @Schema(description = "客户编号-售达方", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotEmpty(message = "客户编号-售达方不能为空")
    private String partn_numb; // 客户编号-售达方 CHAR10

    @Schema(description = "客户编号-付款人")
    private String partn_es; // 客户编号-付款人 CHAR10

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

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

    @Valid
    private List<String> conds;

    @Valid
    private List<Source> sources;

    @Schema(description = "销售订单抬头信息")
    @Data
    public static class Head {
        @Schema(description = "销售凭证类型", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotEmpty(message = "销售凭证类型不能为空")
        private String doc_type; // 销售凭证类型 CHAR4

        @Schema(description = "销售组织", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotEmpty(message = "销售组织不能为空")
        private String sales_org; // 销售组织 CHAR4

        @Schema(description = "分销渠道", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotEmpty(message = "分销渠道不能为空")
        private String distr_chan; // 分销渠道 CHAR2

        @Schema(description = "产品组", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotEmpty(message = "产品组不能为空")
        private String division; // 产品组 CHAR2

        @Schema(description = "要求的交货日期(YYYY-MM-DD)", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotNull(message = "要求的交货日期不能为空")
        private LocalDateTime req_date_h; // 要求的交货日期 DATS8

        @Schema(description = "销售组")
        private String sales_grp; // 销售组 CHAR3

        @Schema(description = "销售办事处")
        private String sales_off; // 销售办事处 CHAR4

        @Schema(description = "业务分类(默认值10-自产，退货订单必须填写)")
        private String cust_grp1 = "10"; // 业务分类 CHAR3

        @Schema(description = "客户参考(销售合同编号)")
        private String purch_no_c; // 客户参考 CHAR35

        @Schema(description = "名称(销售合同名称)")
        private String name; // 名称 CHAR35

        @Schema(description = "参考(外部单据编号，默认会用bskey赋值)")
        private String ref_1; // 参考 CHAR12

        @Schema(description = "客户参考日期(YYYY-MM-DD)")
        private LocalDate purch_date; // 客户参考日期 DATS8

        @Schema(description = "订单原因(退货订单必须填写，默认值Z06-其他原因)")
        private String ord_reason = "Z06"; // 订单原因 CHAR3

        @Schema(description = "货币码")
        private String currency; // 货币码 CUKY5

        @Schema(description = "客户税分类(0-无税,1-必须上税。创建客户销售视图时需要，默认值1)")
        private String taxclass = "1"; // 客户税分类 CHAR1
    }

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

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

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

        @Schema(description = "存储地点", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotEmpty(message = "存储地点不能为空")
        private String store_loc; // 存储地点 CHAR4

        @Schema(description = "销售单位(使用基本计量单位)", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotEmpty(message = "销售单位不能为空")
        private String sales_unit; // 销售单位 UNIT3

        @Schema(description = "使用标识(开票类型)", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotEmpty(message = "使用标识不能为空")
        private String dlvschduse; // 使用标识 CHAR3

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

        @Schema(description = "税分类(默认从客户和物料基础数据带出,创建物料销售视图时默认值为1-13%)")
        private String tax_class1; // 税分类 CHAR1

        @Schema(description = "项目类别")
        private String item_categ; // 项目类别 CHAR4

        @Schema(description = "装运地点")
        private String ship_point; // 装运地点 CHAR4

        @Schema(description = "物料科目分配组(Z1-主营业务,Z2-其它业务，创建物料销售视图时必须填写)")
        private String acct_assgt; // 物料科目分配组 CHAR2
    }

    @Schema(description = "销售订单条件信息")
    @Data
    public static class Cond {
        @Schema(description = "行号", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotNull(message = "行号不能为空")
        private Integer itm_number; // 行号 NUMC6

        @Schema(description = "条件类型", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotEmpty(message = "条件类型不能为空")
        private String cond_type; // 条件类型 CHAR4

        @Schema(description = "条件金额(保留9位小数)", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotNull(message = "条件金额不能为空")
        private BigDecimal cond_value; // 条件金额 DEC28,9

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

        @Schema(description = "条件单位(使用基本计量单位)", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotEmpty(message = "条件单位不能为空")
        private String cond_unit; // 条件单位 UNIT3

        @Schema(description = "条件定价单位(固定值1)", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotNull(message = "条件定价单位不能为空")
        private Integer cond_p_unt = 1; // 条件定价单位 DEC5
    }

    @Schema(description = "来料加工原料信息")
    @Data
    public static class Source {
        @Schema(description = "行号", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotNull(message = "行号不能为空")
        private Integer itm_number; // 行号 NUMC6

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

        @Schema(description = "原料物料描述")
        private String mat_desc; // 原料物料描述 CHAR40

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

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

        @Schema(description = "备注")
        private String remark; // 备注 CHAR255
    }
}
