package com.cool.store.vo;

import com.cool.store.dto.partner.PartnerOpenNewShopPageDTO;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

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

/**
 * @Author suzhuhong
 * @Date 2024/4/1 11:30
 * @Version 1.0
 */
@Data
public class PartnerOpenNewShopPageVO {

    @ApiModelProperty("记录id")
    private Long recordId;

    @ApiModelProperty("线索ID")
    private Long lineId;

    @ApiModelProperty("加盟商编号")
    private String partnerNum;

    @ApiModelProperty("线索名称")
    private String username;

    @ApiModelProperty("手机号")
    private String mobile;

    @ApiModelProperty("意向加盟区域")
    private String wantShopAreaName;

    @ApiModelProperty("线索标签")
    private List<String> userPortraitList;

    @ApiModelProperty("意向开店数量")
    private Integer wantShopNum;

    @ApiModelProperty("扩展经理名称")
    private String developmentManagerUserName;

    @ApiModelProperty("线索来源名称")
    private String lineSourceName;

    @ApiModelProperty("加盟时间")
    private Date joinTime;

    @ApiModelProperty("审核状态 0待审核 1通过 2不通过")
    private Integer auditResult;

    public static List<PartnerOpenNewShopPageVO> convertList(List<PartnerOpenNewShopPageDTO> list, Map<Long, Date> joinTimeMap, Map<Long, String>  wantShopAreaMap,
                                                             Map<String, String> userNameMap, Map<Integer, String> channelMap, Map<Long, String> userPortraitMap){
        if(CollectionUtils.isEmpty(list)){
            return Lists.newArrayList();
        }
        List<PartnerOpenNewShopPageVO> resultList = new ArrayList<>();
        for (PartnerOpenNewShopPageDTO page : list) {
            PartnerOpenNewShopPageVO result = new PartnerOpenNewShopPageVO();
            result.setRecordId(page.getRecordId());
            result.setLineId(page.getLineId());
            result.setPartnerNum(page.getPartnerNum());
            result.setUsername(page.getUsername());
            result.setMobile(page.getMobile());
            result.setWantShopAreaName(wantShopAreaMap.get(page.getWantShopAreaId()));
            result.setWantShopNum(page.getWantShopNum());
            result.setDevelopmentManagerUserName(userNameMap.get(page.getDevelopmentManager()));
            result.setLineSourceName(channelMap.get(page.getLineSource()));
            result.setJoinTime(joinTimeMap.get(page.getLineId()));
            result.setAuditResult(page.getAuditResult());
            List<String> userPortraitList = new ArrayList<>();
            if(StringUtils.isNotBlank(page.getUserPortrait())){
                String[] parts = page.getUserPortrait().split(",");
                for (String part : parts) {
                    String trimmedPart = part.trim();
                    if (StringUtils.isNotBlank(trimmedPart)) {
                        String s = userPortraitMap.get(Long.valueOf(part));
                        if(StringUtils.isNotBlank(s)){
                            userPortraitList.add(s);
                        }
                    }
                }
                result.setUserPortraitList(userPortraitList);
            }
            resultList.add(result);
        }
        return resultList;
    }



}
