package com.cool.store.request;

import com.cool.store.constants.CommonConstants;
import com.cool.store.entity.OrderSysInfoDO;
import com.cool.store.enums.JoinModeEnum;
import com.cool.store.enums.OrderSysTypeEnum;
import com.cool.store.enums.SignTypeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.Objects;

@Data
public class OrderSysInfoRequest {
    
    @ApiModelProperty(hidden = true)
    private Integer type;

    @ApiModelProperty(value = "店铺编码")
    private String shopCode;

    @ApiModelProperty(value = "店铺ID" ,required = true)
    @NotNull(message = "门店id不能为空")
    private Long shopId;

    @ApiModelProperty(value = "副总裁" )
    private String xgjVicePresident;

    @ApiModelProperty(value = "新管家对应组织id" )
    private String xgjRegionId;

    @ApiModelProperty(value = "新管家对应组织name" )
    private String xgjRegionName;

    @ApiModelProperty(value = "收件省" )
    private String addresseeProvince;

    @ApiModelProperty(value = "收件市" )
    private String addresseeCity;

    @ApiModelProperty(value = "收件区" )
    private String addresseeDistrict;

    @ApiModelProperty(value = "详细地址" )
    private String addresseeAddress;

    @ApiModelProperty(value = "报货物流仓库（编码）" )
    private String declareGoodsLogisticsWarehouse;

    @ApiModelProperty(value = "报货类型 0-按周报货 1-按月报货 2-自提" )
    private String declareGoodsType;

    @ApiModelProperty(value = "报货日期 数组格式\"[{ 报货日期 \"declareGoods\": \"\",送货日期\"deliverGoods\":\"\"}]" )
    private String declareGoodsDate;

    @ApiModelProperty(value = "仓库配送日期" )
    private String warehouseDeliveryDate;

    @ApiModelProperty(value = "订货信息创建时间" )
    private Date orderCreateTime;

    @ApiModelProperty(value = "订货信息修改时间" )
    private Date orderUpdateTime;

    @ApiModelProperty(value = "订货信息创建人" )
    private String orderCreateUser;

    @ApiModelProperty(value = "订货信息修改人" )
    private String orderUpdateUser;

    @ApiModelProperty(value = "收款公司名称" )
    private String receivingFirmName;

    @ApiModelProperty(value = "收款公司民生银行账号" )
    private String receivingMsBankAccount;

    @ApiModelProperty(value = "收款公司民生银行支行" )
    private String receivingMsBankBranch;

    @ApiModelProperty(value = "银行银联号" )
    private String bankUnionPayAccount;

    @ApiModelProperty(value = "总部订货收款创建时间" )
    private Date receivingCreateTime;

    @ApiModelProperty(value = "总部订货收款修改时间" )
    private Date receivingUpdateTime;

    @ApiModelProperty(value = "总部订货收款创建人" )
    private String receivingCreateUser;

    @ApiModelProperty(value = "总部订货收款修改人" )
    private String receivingUpdateUser;

    @ApiModelProperty("订货方式，0先款后货、1先货后款")
    private Integer orderType;
    
    public OrderSysInfoDO toOrderSysInfoDO() {
        OrderSysInfoDO orderSysInfoDO = new OrderSysInfoDO();
        orderSysInfoDO.setShopId(this.shopId);
        orderSysInfoDO.setXgjVicePresident(this.xgjVicePresident);
        orderSysInfoDO.setXgjRegionId(this.xgjRegionId);
        orderSysInfoDO.setXgjRegionName(this.xgjRegionName);
        orderSysInfoDO.setAddresseeProvince(this.addresseeProvince);
        orderSysInfoDO.setAddresseeCity(this.addresseeCity);
        orderSysInfoDO.setAddresseeDistrict(this.addresseeDistrict);
        orderSysInfoDO.setAddresseeAddress(this.addresseeAddress);
        orderSysInfoDO.setDeclareGoodsLogisticsWarehouse(this.declareGoodsLogisticsWarehouse);
        orderSysInfoDO.setDeclareGoodsType(this.declareGoodsType);
        orderSysInfoDO.setDeclareGoodsDate(this.declareGoodsDate);
        orderSysInfoDO.setWarehouseDeliveryDate(this.warehouseDeliveryDate);
    
        orderSysInfoDO.setReceivingFirmName(this.receivingFirmName);
        orderSysInfoDO.setReceivingMsBankAccount(this.receivingMsBankAccount);
        orderSysInfoDO.setReceivingMsBankBranch(this.receivingMsBankBranch);
        orderSysInfoDO.setBankUnionPayAccount(this.bankUnionPayAccount);
      
        return orderSysInfoDO;
    }
    public Boolean check(Integer joinMode){
        if (Objects.equals(this.type, OrderSysTypeEnum.ORDER_SYS_TYPE_1.getType())){
            if (StringUtils.isAnyBlank(this.xgjRegionId,this.xgjVicePresident,this.declareGoodsDate,this.declareGoodsLogisticsWarehouse,this.declareGoodsType)){
                return false;
            }
        }
        if (Objects.equals(this.type, OrderSysTypeEnum.ORDER_SYS_TYPE_2.getType())){
            //自由店只需要门店编码
            if (Objects.equals(joinMode, JoinModeEnum.OWN_STORE.getCode())&&this.shopCode!=null){
                return true;
            }
            if (Objects.equals(joinMode, JoinModeEnum.FLAGSHIP_STORE.getCode())&&this.shopCode!=null){
                return true;
            }
            if (StringUtils.isBlank(this.shopCode)) {
                return false;
            }
            if (!CommonConstants.INDEX_ONE.equals(this.orderType) && StringUtils.isAnyBlank(this.receivingFirmName,this.receivingMsBankAccount,this.receivingMsBankBranch,this.bankUnionPayAccount)){
                return false;
            }
        }
        return true;
    }
}