package com.cool.store.request;

import com.alibaba.fastjson.JSONObject;
import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils;
import com.cool.store.entity.ShopRentInfoDO;
import com.cool.store.enums.RentTypeEnum;
import com.cool.store.enums.ShopRentTypeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @author zhangchenbiao
 * @FileName: UploadRentContractRequest
 * @Description:上传租赁合同
 * @date 2024-04-16 11:38
 */
@Data
public class AddRentContractRequest {

    @ApiModelProperty("店铺id")
    private Long shopId;

    @ApiModelProperty("铺位id")
    private Long pointId;

    @NotNull
    @ApiModelProperty("租赁类型 1铺位直租 2自有铺位")
    private Integer rentType;

    @ApiModelProperty("签约日期")
    private Date signTime;

    @ApiModelProperty("合同开始日期")
    private Date contractStartTime;

    @ApiModelProperty("合同结束日期")
    private Date contractEndTime;

    @ApiModelProperty("签约年限")
    private Integer contractMonths;

    @ApiModelProperty("店铺租金 1固定租金 2非固定租金")
    private Integer shopRentType;

    @ApiModelProperty("月租金")
    private String monthRent;

    @ApiModelProperty("第一年月租金")
    private String firstYearMonthRent;

    @ApiModelProperty("第二年月租金")
    private String secondYearMonthRent;

    @ApiModelProperty("第三年月租金")
    private String thirdYearMonthRent;

    @Size(max = 3, message = "最多上传三张租赁合同")
    @ApiModelProperty("合同图片")
    private List<String> contractPic;

    @Size(max = 3, message = "最多上传三张房产证明")
    @ApiModelProperty("房产证明")
    private List<String> houseCertificatePic;

    @ApiModelProperty(value = "当前线索id", hidden = true)
    private Long curLineId;

    public boolean check(){
        if(Objects.isNull(shopId) && Objects.isNull(pointId)){
            return false;
        }
        if(RentTypeEnum.OWN.getCode().equals(rentType)){
            if(CollectionUtils.isEmpty(houseCertificatePic) || houseCertificatePic.size() > 3){
                return false;
            }
            return true;
        }
        if(Objects.isNull(signTime) || Objects.isNull(contractStartTime) || Objects.isNull(contractEndTime)){
            return false;
        }
        if(Objects.isNull(contractMonths) || Objects.isNull(shopRentType)){
            return false;
        }
        if(ShopRentTypeEnum.FIXED.getCode().equals(shopRentType)){
            if(StringUtils.isBlank(monthRent)){
                return false;
            }
        }
        if(ShopRentTypeEnum.NOT_FIXED.getCode().equals(shopRentType)){
            if(StringUtils.isAnyBlank(firstYearMonthRent, secondYearMonthRent, thirdYearMonthRent)){
                return false;
            }
        }
        if(CollectionUtils.isEmpty(contractPic) || contractPic.size() > 3){
            return false;
        }
        return true;
    }

    public static ShopRentInfoDO convertDO(AddRentContractRequest param){
        if(Objects.isNull(param)){
            return null;
        }
        ShopRentInfoDO shopRentInfoDO = new ShopRentInfoDO();
        shopRentInfoDO.setShopId(param.getShopId());
        shopRentInfoDO.setPointId(param.getPointId());
        shopRentInfoDO.setRentType(param.getRentType());
        shopRentInfoDO.setSignTime(param.getSignTime());
        shopRentInfoDO.setContractStartTime(param.getContractStartTime());
        shopRentInfoDO.setContractEndTime(param.getContractEndTime());
        shopRentInfoDO.setContractMonths(param.getContractMonths());
        shopRentInfoDO.setShopRentType(param.getShopRentType());
        shopRentInfoDO.setMonthRent(param.getMonthRent());
        shopRentInfoDO.setFirstYearMonthRent(param.getFirstYearMonthRent());
        shopRentInfoDO.setSecondYearMonthRent(param.getSecondYearMonthRent());
        shopRentInfoDO.setThirdYearMonthRent(param.getThirdYearMonthRent());
        shopRentInfoDO.setContractPic(JSONObject.toJSONString(param.getContractPic()));
        shopRentInfoDO.setHouseCertificatePic(JSONObject.toJSONString(param.getHouseCertificatePic()));
        return shopRentInfoDO;
    }

}
