package com.cool.store.vo;

import cn.hutool.core.date.DateUtil;
import com.cool.store.entity.HyPartnerLineInfoDO;
import com.cool.store.entity.HyPartnerUserInfoDO;
import com.cool.store.utils.CoolDateUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * @Author suzhuhong
 * @Date 2023/5/30 15:56
 * @Version 1.0
 */
@Data
@ApiModel
public class PartnerLineInfoVO {

    @ApiModelProperty("")
    private Long lineId;

    @ApiModelProperty("hy_partner_user_info.partner_id")
    private String partnerId;

    @ApiModelProperty("流程阶段:1意向申请审核;2预约面试时间;3加盟资格面试;4分配选址开发经理;5商圈点位评估;6上传店铺租赁信息;7完善加盟签约信息;8支付加盟费用;9签订加盟合同")
    private String workflowStage;

    @ApiModelProperty("流程子状态")
    private String workflowStatus;

    @ApiModelProperty("线索状态:0公海线索;1跟进中;2合作中;3黑名单")
    private Integer lineStatus;

    @ApiModelProperty("招商经理")
    private String investmentManager;

    @ApiModelProperty("开发主管")
    private String developmentDirector;

    @ApiModelProperty("开发经理")
    private String developmentManager;

    @ApiModelProperty("截止时间")
    private String deadline;

    @ApiModelProperty("通过原因")
    private String passReason;

    @ApiModelProperty("公开拒绝原因")
    private String rejectPublicReason;

    @ApiModelProperty("真实拒绝原因")
    private String rejectRealReason;

    @ApiModelProperty("证明文件或凭证")
    private String certifyFile;

    @ApiModelProperty("冷静期首次登录 是-true  否-false")
    private Boolean coolingPeriodFirstLoginFlag;

    @ApiModelProperty("加盟商用户名称")
    private String partnerUserName;

    @ApiModelProperty("加盟商用户手机号")
    private String partnerUserPhone;

    @ApiModelProperty("结束操作人ID")
    private String closeUserId ;

    @ApiModelProperty("结束操作人名称")
    private String closeUserName ;

    @ApiModelProperty("结束时间")
    private String closeDate ;

    /**
     *
     * @param lineList
     * @return
     */
    public static List<PartnerLineInfoVO> convertList(List<HyPartnerLineInfoDO> lineList, Map<String, String> userNamePhoneMap, Map<String, HyPartnerUserInfoDO> partnerMap){
        List<PartnerLineInfoVO> resultList = new ArrayList<>();
        for (HyPartnerLineInfoDO line : lineList) {
            PartnerLineInfoVO result = new PartnerLineInfoVO();
            result.setLineId(line.getId());
            result.setPartnerId(line.getPartnerId());
            result.setCertifyFile(line.getCertifyFile());
            result.setWorkflowStage(line.getWorkflowStage());
            result.setWorkflowStatus(line.getWorkflowStatus());
            result.setLineStatus(line.getLineStatus());
            String deadLine = DateUtil.format(line.getDeadline(), CoolDateUtils.DATE_FORMAT_SEC_2);
            result.setDeadline(deadLine);
            result.setPassReason(line.getPassReason());
            result.setRejectPublicReason(line.getRejectPublicReason());
            result.setRejectRealReason(line.getRejectRealReason());
            result.setCertifyFile(line.getCertifyFile());
            result.setCloseUserId(line.getCloseUserId());
            result.setCloseUserName(userNamePhoneMap.get(line.getCloseUserId()));
            HyPartnerUserInfoDO partnerUser = partnerMap.get(line.getPartnerId());
            String partnerUserName = Optional.ofNullable(partnerUser).map(HyPartnerUserInfoDO::getUsername).orElse(StringUtils.EMPTY);
            String partnerUserPhone = Optional.ofNullable(partnerUser).map(HyPartnerUserInfoDO::getMobile).orElse(StringUtils.EMPTY);
            result.setPartnerUserName(partnerUserName);
            result.setPartnerUserPhone(partnerUserPhone);
            String closeDate = DateUtil.format(line.getCloseTime(), CoolDateUtils.DATE_FORMAT_SEC_7);
            result.setCloseDate(closeDate);
            resultList.add(result);
        }
        return resultList;
    }


}
