package com.cool.store.vo;

import cn.hutool.core.date.DateUtil;
import com.cool.store.dto.partner.PartnerIntentApplyInfoDTO;
import com.cool.store.entity.HyPartnerUserInfoDO;
import com.cool.store.utils.CoolDateUtils;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

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


/**
 * @Author suzhuhong
 * @Date 2023/5/30 20:11
 * @Version 1.0
 */
@Data
@ApiModel
public class PartnerIntentApplyInfoVO {

    @ApiModelProperty("")
    private Long id;

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

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

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

    @ApiModelProperty("hy_partner_line_info.id")
    private Long lineId;

    @ApiModelProperty("常驻区域")
    private String liveArea;

    @ApiModelProperty("意向开店区域")
    private String wantShopArea;

    @ApiModelProperty("意向开店区域")
    private String wantShopAreaName;

    @ApiModelProperty("0不接受调剂、1全国调剂、2省内调剂、3市内调剂")
    private Integer acceptAdjustType;

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

    @ApiModelProperty("阶段提交时间")
    private String partnerSubmitTime;

    @ApiModelProperty("阶段状态")
    private String WorkflowStatus;


    public static List<PartnerIntentApplyInfoVO> convertList(List<PartnerIntentApplyInfoDTO> list, Map<String, HyPartnerUserInfoDO> infoDOMap, Map<String, String> wantShopAreaNameMap, String workflowStatus){
        if(CollectionUtils.isEmpty(list)){
            return Lists.newArrayList();
        }
        List<PartnerIntentApplyInfoVO> resultList = new ArrayList<>();
        for (PartnerIntentApplyInfoDTO partnerIntentApplyInfoDTO : list) {
            PartnerIntentApplyInfoVO partnerIntentApplyInfoVO = new PartnerIntentApplyInfoVO();
            partnerIntentApplyInfoVO.setId(partnerIntentApplyInfoDTO.getId());
            partnerIntentApplyInfoVO.setPartnerId(partnerIntentApplyInfoDTO.getPartnerId());
            partnerIntentApplyInfoVO.setLineId(partnerIntentApplyInfoDTO.getPartnerLineId());
            partnerIntentApplyInfoVO.setPartnerSubmitTime( DateUtil.format(partnerIntentApplyInfoDTO.getPartnerSubmitTime(), CoolDateUtils.DATE_FORMAT_SEC_2));
            partnerIntentApplyInfoVO.setAcceptAdjustType(partnerIntentApplyInfoDTO.getAcceptAdjustType());
            partnerIntentApplyInfoVO.setLiveArea(partnerIntentApplyInfoDTO.getLiveArea());
            partnerIntentApplyInfoVO.setWantShopArea(partnerIntentApplyInfoDTO.getWantShopArea());
            String deadLine = DateUtil.format(partnerIntentApplyInfoDTO.getDeadline(), CoolDateUtils.DATE_FORMAT_SEC_2);
            partnerIntentApplyInfoVO.setDeadline(deadLine);
            HyPartnerUserInfoDO infoDOMapOrDefault = infoDOMap.getOrDefault(partnerIntentApplyInfoDTO.getPartnerId(), new HyPartnerUserInfoDO());
            partnerIntentApplyInfoVO.setPartnerUserName(infoDOMapOrDefault.getUsername());
            partnerIntentApplyInfoVO.setPartnerUserPhone(infoDOMapOrDefault.getMobile());
            partnerIntentApplyInfoVO.setWorkflowStatus(workflowStatus);
            partnerIntentApplyInfoVO.setWantShopAreaName(wantShopAreaNameMap.get(partnerIntentApplyInfoDTO.getWantShopArea()));
            resultList.add(partnerIntentApplyInfoVO);
        }
        return resultList;
    }

}
