package com.cool.store.vo.interview;

import com.cool.store.dto.interview.LineInterviewPageDTO;
import com.cool.store.utils.StringUtil;
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.List;
import java.util.Map;

/**
 * @author zhangchenbiao
 * @FileName: LineInterviewPageVO
 * @Description:
 * @date 2024-03-19 15:55
 */
@Data
public class LineInterviewPageVO {

    @ApiModelProperty("面试id")
    private Long interviewId;

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

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

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

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

    @ApiModelProperty("用户标签")
    private List<String> userPortraitList;

    @ApiModelProperty("计划开始时间")
    private String startTime;

    @ApiModelProperty("计划结束时间")
    private String endTime;

    @ApiModelProperty("面试状态 1待面试 2待审核 3审批通过 4不通过")
    private Integer interviewStatus;

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

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

    @ApiModelProperty("实际开始时间")
    private String actualStartTime;

    @ApiModelProperty("实际结束时间")
    private String actualEndTime;

    @ApiModelProperty("面审人")
    private String interviewerUsername;

    @ApiModelProperty("房间id")
    private String roomId;

    public static List<LineInterviewPageVO> convertList(List<LineInterviewPageDTO> list, Map<Long, String> userPortraitMap, Map<String, String> userNameMap, Map<Long, String> cityNameMap, Map<Integer, String> channelMap){
        if(CollectionUtils.isEmpty(list)){
            return Lists.newArrayList();
        }
        List<LineInterviewPageVO> resultList = new ArrayList<>();
        for (LineInterviewPageDTO lineInterviewPage : list) {
            LineInterviewPageVO result = new LineInterviewPageVO();
            result.setInterviewId(lineInterviewPage.getInterviewId());
            result.setLineId(lineInterviewPage.getLineId());
            result.setUsername(lineInterviewPage.getUsername());
            result.setMobile(lineInterviewPage.getMobile());
            result.setWantShopArea(cityNameMap.get(lineInterviewPage.getWantShopAreaId()));
            result.setStartTime(lineInterviewPage.getStartTime());
            result.setEndTime(lineInterviewPage.getEndTime());
            result.setInterviewStatus(lineInterviewPage.getInterviewStatus());
            result.setInvestmentManagerUsername(userNameMap.get(lineInterviewPage.getInvestmentManager()));
            result.setLineSourceName(channelMap.get(lineInterviewPage.getLineSource()));
            result.setActualStartTime(lineInterviewPage.getActualStartTime());
            result.setActualEndTime(lineInterviewPage.getActualEndTime());
            result.setInterviewerUsername(userNameMap.get(lineInterviewPage.getInterviewerUserId()));
            List<String> userPortraitList = new ArrayList<>();
            if(StringUtils.isNotBlank(lineInterviewPage.getUserPortrait())){
                String[] parts = lineInterviewPage.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);
            }
            result.setRoomId(lineInterviewPage.getRoomId());
            resultList.add(result);
        }
        return resultList;
    }


}
