package com.sckw.contract.model.vo.req;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Digits;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author :chenXiaoFei
 * @version :1.0
 * @description :
 * @create :2025-11-06 14:17:00
 */
@Data
public class LogisticListReq implements Serializable {
    @Serial
    private static final long serialVersionUID = 5207417536682160933L;
    /**
     * 合同id 修改时必传
     */
    @Schema(description = "合同id")
    private Long id;

    /**
     * 父合同ID 补充合同
     */
    @Schema(description = "父合同ID")
    @NotNull(message = "父合同ID不能为空")
    private Long pid;

    /**
     * 基础信息
     */
    @Schema(description = "基础信息")
    @NotNull(message = "基础信息不能为空")
    private TradeBaseInfo baseInfo;

    /**
     * 合同文件
     */
    @Schema(description = "合同文件")
    @NotBlank(message = "合同文件不能为空")
    private String contractFile;

    /**
     * 标的信息
     */
    @Schema(description = "标的信息")
    private List<TradeGoodsInfo> goodsInfo;

    /**
     * 备注
     */
    @Schema(description = "备注")
    private String remark;
    @Data
    public static class TradeBaseInfo implements Serializable{

        @Serial
        private static final long serialVersionUID = -5828478625710244673L;

        /**
         * 采购单位id
         */
        @Schema(description = "采购单位id")
        @NotNull(message = "采购单位不能为空")
        private Long purchaseEntId;

        /**
         * 采购单位联系电话
         */
        @Schema(description = "采购单位联系电话")
        @NotBlank(message = "采购单位联系电话不能为空")
        private String purchasePhone;

        /**
         * 供应单位id
         */
        @NotNull(message = "供应单位不能为空")
        @Schema(description = "供应单位id")
        private Long provideEntId;

        /**
         * 供应单位联系电话
         */
        @Schema(description = "供应单位联系电话")
        @NotBlank(message = "供应单位联系电话不能为空")
        private String providePhone;

        /**
         * 合同编号
         */
        @Schema(description = "合同编号")
        @NotBlank(message = "合同编号不能为空")
        @Size(max = 20, message = "合同编号超长")
        private String contractCode;

        /**
         * 合同名称
         */
        @Schema(description = "合同名称")
        @NotBlank(message = "合同名称不能为空")
        @Size(max = 50, message = "合同名称超长")
        private String contractName;

        /**
         * 终止时间
         */
        @DateTimeFormat(pattern = "yyyy-MM-dd")
        @JsonFormat(pattern="yyyy-MM-dd", timezone = "GMT+8")
        @Schema(description = "终止时间")
        private Date endTime;

        /**
         * 签约方式（1线上签约、2线下签约）
         */
        @NotNull(message = "签约方式不能为空")
        @Schema(description = "签约方式")
        private Integer signingWay;

        /**
         * 派车方式 1手动派车、2自动派车
         */
        @NotNull(message = "派车方式不能为空")
        @Schema(description = "派车方式 1-手动派车,2-自动派车")
        private Integer dispatchWay = 1;


        /**
         * 结算方式 (1普通结算，2预付制结算)
         */
        @NotNull(message = "结算方式不能为空")
        @Schema(description = "结算方式 (1普通结算，2记账模式)")
        private Integer settlement;

        /**
         * 生效时间
         */
        @NotNull(message = "生效时间不能为空")
        @DateTimeFormat(pattern = "yyyy-MM-dd")
        @JsonFormat(pattern="yyyy-MM-dd", timezone = "GMT+8")
        @Schema(description = "生效时间")
        private Date startTime;

        /**
         * 业务合同类型（1贸易运输 2原矿转运），未传时后端按贸易运输处理
         */
        @Schema(description = "业务合同类型 1-贸易运输 2-原矿转运", allowableValues = {"1", "2"})
        private Integer transportBizType;

        /**
         * 允许误差（千分比数值，如 5 表示 5‰）；原矿转运时必填
         */
        @Schema(description = "允许误差(千分比)，原矿转运必填")
        private BigDecimal allowedError;

        /**
         * 通用价格
         */
        @Schema(description = "通用价格")
        private BigDecimal commonPrice;



    }
    @Data
    public static class TradeGoodsInfo implements Serializable{
        @Serial
        private static final long serialVersionUID = -7003603561892852639L;

        /**
         * 商品id
         */
        @NotNull(message = "商品不能为空")
        @Schema(description = "商品id")
        private Long goodsId;
        /**
         * 商品名称
         */
        @Schema(description = "商品名称")
        private String goodsName;

        /**
         * 采购数量
         */
        @Schema(description = "采购数量")
        @Digits(integer = 10, fraction = 2, message = "采购数量超长")
        private BigDecimal amount;
        /**
         * 数量单位
         */
        private String amountUnit;

        /**
         * 单价
         */
        @Schema(description = "单价")
        @Digits(integer = 10, fraction = 2, message = "单价超长")
        private BigDecimal price;

        /**
         * 单位
         */
        @Schema(description = "价格单位")
        private String unit;
        /**
         * 生效时间
         */
        @Schema(description = "生效开始时间")
        @NotBlank(message = "生效时间不能为空")
        private Date effectiveStartTime;
        /**
         * 生效时间
         */
        @Schema(description = "生效结束时间")
        @NotBlank(message = "生效时间不能为空")
        private Date effectiveEntTime;
    }
}
