package cn.iocoder.yudao.module.order.vo.orderItem;

import cn.iocoder.yudao.module.order.vo.order.WarehouseInInfoVO;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.*;

import java.math.BigDecimal;
import java.util.*;
import io.swagger.annotations.*;
import javax.validation.constraints.*;

/**
* 订单项 Base VO，提供给添加、修改、详细的子 VO 使用
* 如果子 VO 存在差异的字段，请不要添加到这里，影响 Swagger 文档生成
*/
@Data
public class OrderItemBaseVO {

    @ApiModelProperty(value = "订单ID", required = true)
//    @NotNull(message = "订单ID不能为空")
    private Long orderId;

    @ApiModelProperty(value = "订单编号", required = true)
//    @NotNull(message = "订单编号不能为空")
    private String orderNo;

    @ApiModelProperty(value = "订单类型：1 普货 2 重货 3 泡货")
    private Integer orderItemType;

    @ApiModelProperty(value = "运输方式id", required = true)
//    @NotNull(message = "运输方式id不能为空")
    private Integer transportId;

    @ApiModelProperty(value = "线路ID", required = true)
//    @NotNull(message = "线路ID不能为空")
    private Long lineId;

    @ApiModelProperty(value = "渠道ID")
    private Long channelId;

    @ApiModelProperty(value = "订单项状态详情见字典")
    private Integer itemStatus;

    @ApiModelProperty(value = "商品ID", required = true)
    @NotNull(message = "商品ID不能为空")
    private Long prodId;

    @ApiModelProperty(value = "产品类型")
    private Integer prodType;

    @ApiModelProperty(value = "产品中文标题")
    private String prodTitleZh;

    @ApiModelProperty(value = "产品英文标题")
    private String prodTitleEn;

    @ApiModelProperty(value = "商品第三方链接")
    private String link;

    @ApiModelProperty(value = "品牌ID", required = true)
    private Long brand;

    @ApiModelProperty(value = "0 无牌 1 有牌 2 中性", required = true)
    @NotNull(message = "0 无牌 1 有牌 2 中性不能为空")
    private Integer brandType;

    @ExcelProperty("费用模式")
    @ApiModelProperty(value = "费用模式：无牌价0，有牌价1，中性品牌价2")
    private Integer feeType;

    @ApiModelProperty(value = "是否预付：0 到付 1 预付")
    private Integer isPayAdvance;

    @ApiModelProperty(value = "计费方式：0 运费/清关费 1 全包价")
    private Integer charging;

    @ApiModelProperty(value = "数量")
    private Integer quantity;

    @ApiModelProperty(value = "件数", required = true)
    //@NotNull(message = "件数不能为空")
    private Integer num;

    @ApiModelProperty(value = "单位", required = true)
    //@NotNull(message = "单位不能为空")
    private String unit;

    @ApiModelProperty(value = "箱规")
    private String boxGauge;

    @ApiModelProperty(value = "体积")
    private BigDecimal volume;

    @ApiModelProperty(value = "重量")
    private BigDecimal weight;

    @ApiModelProperty(value = "货值")
    @NotNull(message = "货值不能为空")
    private BigDecimal worth = BigDecimal.ZERO;

    @ApiModelProperty(value = "货值金额单位ID")
    private Integer worthCurrency;

    @ApiModelProperty(value = "商品特性(可选多个特性ID)")
    private String prodAttrIds;

    @ApiModelProperty(value = "结果")
    private String result;

    @ApiModelProperty(value = "结果状态(多个以逗号拼接，状态详情见字典")
    private String resultStatus;

    @ApiModelProperty(value = "是否特价")
    private Boolean specialPriceType;

    @ApiModelProperty(value = "运费单价(成交)")
    private BigDecimal oneSeaFreight;

    @ApiModelProperty(value = "旧运费单价(成交)")
    private BigDecimal oldOneSeaFreight;

    @ApiModelProperty(value = "成本运费(成本)")
    private BigDecimal costSeaFreight;

    @ApiModelProperty(value = "运费(小计)")
    private BigDecimal seaFreight;

    @ApiModelProperty(value = "原来运费(原始)")
    private BigDecimal originalSeaFreight;

    @ApiModelProperty(value = "运费货币单位ID")
    private Integer seaFreightCurrency;

    @ApiModelProperty(value = "运费体积单位")
    private Long seaFreightVolume;

    @ApiModelProperty(value = "清关费单价(成交)")
    private BigDecimal oneClearanceFreight;

    @ApiModelProperty(value = "旧清关费单价(成交)")
    private BigDecimal oldOneClearanceFreight;

    @ApiModelProperty(value = "清关费(小计)")
    private BigDecimal clearanceFreight;

    @ApiModelProperty(value = "原清关费(原始)")
    private BigDecimal originalClearanceFreight;

    @ApiModelProperty(value = "清关费货币单位ID")
    private Integer clearanceFreightCurrency;

    @ApiModelProperty(value = "清关费体积单位")
    private Long clearanceFreightVolume;

    @ApiModelProperty("快递单号")
    private String expressNo;

    @ApiModelProperty(value = "佣金类型：0 无 1 明佣 2 暗佣 3 明+暗")
    private Integer commissionType;

    @ApiModelProperty("明佣金额")
    private BigDecimal plainCommission = BigDecimal.ZERO;

    @ApiModelProperty("暗佣金额")
    private BigDecimal hiddenCommission = BigDecimal.ZERO;

    @ApiModelProperty(value = "重货体积")
    private String wVolume;

    @ApiModelProperty(value = "泡货重量")
    private String vWeight;

    @ApiModelProperty(value = "重货标准基数")
    private BigDecimal weightUnit;

    @ApiModelProperty(value = "泡货标准基数")
    private BigDecimal volumeUnit;


    /**
     * 入仓信息json
     */
    @ApiModelProperty(value = "入仓信息VO")
    @TableField(exist = false)
    private WarehouseInInfoVO warehouseInInfoVO;
    /**
     * 是否仓库入仓新品
     */
    @ApiModelProperty(value = "是否仓库入仓新品 0 下单货物  1 非下单货物-即新品 ")
    private Boolean isWarehouseInAdd;

    /**
     * 入仓信息json
     */
    @ApiModelProperty(value = "入仓信息json")
    private String warehouseInInfo;
     /**
     * 材质
     */
    @ApiModelProperty(value = "材质")
    private String material;

    @ApiModelProperty(value = "活动优惠运费金额(原始单价上进行优惠)")
    private BigDecimal discountFreightPrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "活动优惠运费总金额")
    private BigDecimal discountFreightTotalPrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "活动优惠清关费金额(原始单价上进行优惠)")
    private BigDecimal discountClearanceFeePrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "活动优惠清关费总金额")
    private BigDecimal discountClearanceFeeTotalPrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "是否已定价")
    private Boolean isPriced = Boolean.FALSE;

    @ApiModelProperty(value = "液体清关费单价")
    private BigDecimal liquidClearanceFeePrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "液体运费单价")
    private BigDecimal liquidFreightPrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "带电清关费单价")
    private BigDecimal electrifiedClearanceFeePrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "带电运费单价")
    private BigDecimal electrifiedFreightPrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "品牌清关费单价")
    private BigDecimal brandClearanceFeePrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "品牌运费单价")
    private BigDecimal brandFreightPrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "包装清关费单价")
    private BigDecimal packagingClearanceFeePrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "包装运费单价")
    private BigDecimal packagingFreightPrice = BigDecimal.ZERO;

    @ApiModelProperty(value = "是否特价佣金设置")
    private Boolean specialCommission = Boolean.FALSE;

    @ApiModelProperty(value = "使用的优惠信息")
    private String couponInfo;

    @ApiModelProperty(value = "原订单项id")
    private Long orgItemId;

    @ApiModelProperty(value = "'空运加价运费单价'")
    private BigDecimal markupSeaFreight = BigDecimal.ZERO;

    @ApiModelProperty(value = "'空运加价清关费单价'")
    private BigDecimal markupClearanceFreight = BigDecimal.ZERO;

    @ApiModelProperty(value = "空运清关费来源：1 商品 2 渠道")
    private Integer airClearanceSource;

    @ApiModelProperty(value = "'空运清关费来源数据详情'")
    private String airClearanceInfo;


    @ApiModelProperty(value = "应收运费(成本) = 应收单价 * 原始重泡货标准的收费数据")
    private BigDecimal receivableSeaFreight;

    @ApiModelProperty(value = "应收清关费(成本) = 应收单价 * 原始重泡货标准的收费数据")
    private BigDecimal receivableClearanceFreight;

    @ApiModelProperty(value = "应收收费数量")
    private BigDecimal orgChargeQuantity = BigDecimal.ZERO;

    @ApiModelProperty(value = "应收收费件数")
    private Integer orgChargeNum = 0;

    @ApiModelProperty(value = "应收收费体积")
    private BigDecimal orgChargeVolume = BigDecimal.ZERO;

    @ApiModelProperty(value = "应收收费重量")
    private BigDecimal orgChargeWeight = BigDecimal.ZERO;

    @ApiModelProperty(value = "是否需要单询，0-否，1-是")
    private Integer needOrderInquiry;

    @ApiModelProperty(value = "是否处理过单询异常")
    private Boolean isHandlerOrderInquiryException;

    @ApiModelProperty(value = "是否处理了渠道特性异常")
    private Boolean handlerChannelAttrException;

    public void setWarehouseInInfo(String warehouseInInfo) {
        this.warehouseInInfo = warehouseInInfo;
        this.warehouseInInfoVO = JSONObject.parseObject(warehouseInInfo, WarehouseInInfoVO.class);

    }
    public void setWarehouseInInfoVO(WarehouseInInfoVO warehouseInInfoVO) {
        this.warehouseInInfoVO = warehouseInInfoVO;
        if (Objects.nonNull(warehouseInInfoVO)) {
            this.warehouseInInfo = JSONObject.toJSONString(warehouseInInfoVO);
        }
    }
    public void setOneSeaFreight(BigDecimal oneSeaFreight) {
        this.oneSeaFreight = oneSeaFreight;
        if (Objects.nonNull(this.plainCommission)) {
            this.costSeaFreight = oneSeaFreight.subtract(this.plainCommission);
        }
    }

    public void setPlainCommission(BigDecimal plainCommission) {
        this.plainCommission = plainCommission;
        if (Objects.nonNull(this.oneSeaFreight)) {
            this.costSeaFreight = this.oneSeaFreight.subtract(plainCommission);
        }
    }

}
