package com.cool.store.request;

import com.cool.store.entity.SignFranchiseDO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Column;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@Data
public class AddSignFranchiseRequest {

    @ApiModelProperty("主键，更新时才存在")
    private Long id;

    private Long shopId;

    private Long regionId;

    @NotBlank(message = "加盟签约店铺名称不能为空")
    private String shopName;

    @NotBlank(message = "门店地址不能为空")
    private String detailAddress;

    @ApiModelProperty("加盟品牌")
    @NotBlank(message = "加盟品牌不能为空")
    private String franchiseBrand;

    @ApiModelProperty("【门店类型】：0-无展示门店、1-餐厅店、2-普通门店'")
    @NotNull(message = "门店类型不能为空")
    private Integer storeType;

    @ApiModelProperty("经营模式（0 无 1直营 2加盟）")
    private Integer businessModel;

    @ApiModelProperty("加盟模式（1-加盟部加盟店、2-加盟公司、3-自有加盟、4-强加盟）")
    @NotNull(message = "加盟模式不能为空")
    private Integer joinMode;

    /**
     * SignTypeEnum
     */
    @ApiModelProperty("签约类型,0.转让　1.新签　2.续签　3.迁址　5.新签同异业转化，6-老店新开 7-直营转加盟")
    private Integer signType;

    @ApiModelProperty("品牌使用费比例")
    private String brandFee;

    @ApiModelProperty("是否有营业执照 0-是 1-否")
    private Integer isBusinessLicense;

    @ApiModelProperty("是否有食营 0-是 2-否[二证合一] 3-否[[三小一摊] 4-否[暂未办理]")
    private Integer isFoodLicense;

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

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

    @ApiModelProperty("用印次数")
    private String impressionNum;

    @ApiModelProperty("营业开始时间（日期不重要传分秒即可）")
    private Date businessStartHours;
    @ApiModelProperty("营业结束时间（日期不重要传分秒即可）")
    private Date businessEndHours;

    @ApiModelProperty("非常规营业时间原因")
    private String irregularReason;

    @ApiModelProperty("备注")
    private String remark;

    @ApiModelProperty("是否补签")
    private Integer resign;

    @ApiModelProperty("加盟商联系方式")
    private String mobile;

    @ApiModelProperty("合同编码")
    private String contractCode;
    @ApiModelProperty("合同金额")
    private String contractAmount;
    @ApiModelProperty("合伙签约人1")
    private String partnershipSignatoryFirst;
    @ApiModelProperty("合伙签约人2")
    private String partnershipSignatorySecond;
    //签约人2身份证号
    @ApiModelProperty("签约人2身份证号")
    private String partnershipSignatorySecondIdNumber;
    //签约人2手机号
    @ApiModelProperty("签约人2手机号")
    private String partnershipSignatorySecondMobile;
    //'保护距离 / m'
    @ApiModelProperty("保护距离 / m")
    @NotNull(message = "保护距离不能为空")
    private Integer protectiveDistance;
    //介绍人
    @ApiModelProperty("介绍人")
    private String introducer;
    //介绍门店
    @ApiModelProperty("介绍门店")
    private String introduceStore;
    //介绍奖
    @ApiModelProperty("介绍奖")
    private String introductionAward;
    //签约人1第几家分店
    @ApiModelProperty("签约人1第几家分店")
    private Integer partnershipSignatoryFirstWhichStore;

    //省
    @ApiModelProperty("省")
    @NotBlank(message = "省不能为空")
    private String province;
    //省code
    @ApiModelProperty("省code")
    private Integer provinceCode;
    //市
    @ApiModelProperty("市")
    @NotBlank(message = "市不能为空")
    private String city;
    //市code
    @ApiModelProperty("市code")
    private Integer cityCode;
    //区
    @ApiModelProperty("区")
    @NotBlank(message = "区不能为空")
    private String district;
    //区code
    @ApiModelProperty("区code")
    private Integer districtCode;

    @NotNull(message = "所属管理区域id不能为空")
    @ApiModelProperty("所属管理区域id")
    private Long managerRegionId;

    @ApiModelProperty("门店装修属性 0-新开店 1-老店新开 2-老店翻新 3-迁址")
    @NotNull(message = "门店属性（装修）不能为空")
    private Integer shopDecorationAttributes;

    @ApiModelProperty("是否统管 ： 1-统管，0-不统管")
    private Integer unifiedManagement;



    public SignFranchiseDO toSignFranchiseDO() {
        SignFranchiseDO signFranchiseDO = new SignFranchiseDO();
        signFranchiseDO.setId(this.id);
        signFranchiseDO.setShopId(this.shopId);
        signFranchiseDO.setSignType(this.signType);
        signFranchiseDO.setBrandFee(this.brandFee);
        signFranchiseDO.setIsBusinessLicense(this.isBusinessLicense);
        signFranchiseDO.setIsFoodLicense(this.isFoodLicense);
        signFranchiseDO.setContractStartTime(this.contractStartTime);
        signFranchiseDO.setContractEndTime(this.contractStartEndTime);
        signFranchiseDO.setImpressionNum(this.impressionNum);
//        signFranchiseDO.setBusinessStartHours(setMill(this.businessStartHours));
//        signFranchiseDO.setBusinessEndHours(setMill(this.businessEndHours));
//        signFranchiseDO.setIrregularReason(this.irregularReason);
        signFranchiseDO.setRemark(this.remark);
        signFranchiseDO.setResign(this.resign);
        signFranchiseDO.setMobile(this.mobile);
        signFranchiseDO.setContractCode(this.contractCode);
        signFranchiseDO.setContractAmount(this.contractAmount);
        signFranchiseDO.setPartnershipSignatoryFirst(this.partnershipSignatoryFirst);
        signFranchiseDO.setPartnershipSignatorySecond(this.partnershipSignatorySecond);
        signFranchiseDO.setBusinessModel(this.businessModel);
        signFranchiseDO.setPartnershipSignatorySecondIdNumber(this.partnershipSignatorySecondIdNumber);
        signFranchiseDO.setPartnershipSignatorySecondMobile(this.partnershipSignatorySecondMobile);
        signFranchiseDO.setProtectiveDistance(this.protectiveDistance);
        signFranchiseDO.setIntroducer(this.introducer);
        signFranchiseDO.setIntroduceStore(this.introduceStore);
        signFranchiseDO.setIntroductionAward(this.introductionAward);
        signFranchiseDO.setPartnershipSignatoryFirstWhichStore(this.partnershipSignatoryFirstWhichStore);
        signFranchiseDO.setUnifiedManagement(this.unifiedManagement);
        return signFranchiseDO;
    }

    /**
     * 丢弃毫秒日期
     * @param date
     * @return
     */
    private Date setMill(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.MILLISECOND, 0);
        Date dateWithoutMilliseconds = calendar.getTime();
        return dateWithoutMilliseconds;

    }
}
