package com.cool.store.request;

import com.cool.store.entity.InitiatingDO;
import com.cool.store.utils.StringUtil;
import io.swagger.models.auth.In;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

@Data
public class InitiatingRequest {

    private Long lineId;

    private String signName;

    private String idCardNo;

    private String businessLicenseCode;

    private String mobile;

    private String idCardAddress;

    private String businessLicenseAddress;

    private String title;

    private String apply_user;

    private String apply_user_name;

    private String apply_date;

    private String jms_id_card;

    private String jms_id_card_address;

    private String jms_name;

    private BigDecimal lybzj;

    private BigDecimal lybzjwb;

    private String lybzjdx;

    private String jms_mobile;

    private String annex1;

    private String annex2;

    private String annex3;

    private Integer qy_year;

    private Integer qy_month;

    private Integer qy_day;

    private Integer jy_year;

    private Integer jy_month;

    private Integer jy_day;

    private String yxjzz;

    private Integer xyqx_month;

    private BigDecimal jmf;

    private BigDecimal jmfwb;

    private String jmfdx;

    private BigDecimal jmyxj;

    private BigDecimal jmyxjwb;

    private String jmyxjdx;

    private String csfz;

    private String jmsxx;

    private String annex4;

    private String annex5;

    private String annex6;

    private String annex7;

    private String dkr;

    private String dkrq;

    private Integer jm_type;

    private Integer jms_type;

    private String jm_csgs;

    private String csfzName;

    private Date signStartTime;

    private Date signEndTime;


    public InitiatingDO toInitiatingDO() {
        InitiatingDO initiatingDO = new InitiatingDO();
        LocalDate currentDate = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        // 格式化日期并输出
        String dateTime = currentDate.format(formatter);
        initiatingDO.setTitle("加盟意向协议-" + this.signName + "-" + dateTime);
        initiatingDO.setApply_date(this.apply_date);
        initiatingDO.setJms_id_card(this.idCardNo);
        if (StringUtil.isNotBlank(this.businessLicenseAddress)) {
            initiatingDO.setJms_id_card_address(this.businessLicenseAddress);
        } else if (StringUtil.isNotBlank(this.idCardAddress)) {
            initiatingDO.setJms_id_card_address(this.idCardAddress);
        }
        if (StringUtil.isNotBlank(this.businessLicenseCode)) {
            initiatingDO.setJms_id_card(this.businessLicenseCode);
        } else if (StringUtil.isNotBlank(this.idCardNo)) {
            initiatingDO.setJms_id_card(this.idCardNo);
        }
        initiatingDO.setJms_name(this.signName);
        initiatingDO.setLybzj(this.lybzj);
        initiatingDO.setLybzjwb(this.lybzj);
        initiatingDO.setLybzjdx(this.lybzjdx);
        initiatingDO.setJms_mobile(this.mobile);
        initiatingDO.setAnnex1(this.annex1);
        initiatingDO.setAnnex2(this.annex2);
        initiatingDO.setAnnex3(this.annex3);
        initiatingDO.setQy_year(timeUtils(this.signStartTime,"year"));
        initiatingDO.setQy_month(timeUtils(this.signStartTime,"month"));
        initiatingDO.setQy_day(timeUtils(this.signStartTime,"day"));
        initiatingDO.setJy_year(timeUtils(this.signEndTime,"year"));
        initiatingDO.setJy_month(timeUtils(this.signEndTime,"month"));
        initiatingDO.setJy_day(timeUtils(this.signEndTime,"day"));
        initiatingDO.setYxjzz(this.yxjzz);
        initiatingDO.setXyqx_month(this.xyqx_month);
        initiatingDO.setJmf(this.jmf);
        initiatingDO.setJmfwb(this.jmf);
        initiatingDO.setJmfdx(this.jmfdx);
        initiatingDO.setJmyxj(this.jmyxj);
        initiatingDO.setJmyxjwb(this.jmyxj);
        initiatingDO.setCsfz(this.csfz);
        initiatingDO.setJmsxx(this.jmsxx);
        initiatingDO.setAnnex4(this.annex4);
        initiatingDO.setAnnex5(this.annex5);
        initiatingDO.setAnnex6(this.annex6);
        initiatingDO.setAnnex7(this.annex7);
        initiatingDO.setDkr(this.dkr);
        initiatingDO.setDkrq(this.dkrq);
        initiatingDO.setJm_type(this.jm_type);
        initiatingDO.setJms_type(this.jms_type);
        initiatingDO.setJm_csgs(this.jm_csgs);
        initiatingDO.setJmyxjdx(this.jmyxjdx);
        return initiatingDO;
    }

    private int timeUtils(Date time, String type) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(time);
        switch (type){
            case "year":
                return calendar.get(Calendar.YEAR);
            case "month":
                return calendar.get(Calendar.MONTH) + 1;
            case "day":
                return  calendar.get(Calendar.DAY_OF_MONTH);
            default:
                return 0;
        }

    }

}
