package com.cool.store.vo.point;

import com.cool.store.entity.PointInfoDO;
import com.cool.store.entity.PointRecommendDO;
import com.cool.store.enums.point.PointStatusEnum;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author zhangchenbiao
 * @FileName: PointRecommendPageVO
 * @Description:
 * @date 2024-04-08 16:11
 */
@Data
public class PointRecommendPageVO {

    @ApiModelProperty("店铺id")
    private Long pointId;

    @ApiModelProperty("铺位名称")
    private String pointName;

    @ApiModelProperty("铺位编号")
    private String pointCode;

    @ApiModelProperty("所属大区")
    private Long regionId;

    @ApiModelProperty("所属站区")
    private String regionNodeName;

    @ApiModelProperty("铺位状态 1.采集中、2.已评估、3.待审核、5.已审核、6.已签约、7.已失效")
    private Integer pointStatus;

    @ApiModelProperty("铺位得分")
    private Integer pointScore;

    @ApiModelProperty("铺位面积")
    private String pointArea;

    @ApiModelProperty("拓展专员")
    private String developmentManagerUsername;

    @ApiModelProperty("拓展时间")
    private Date developmentTime;

    @ApiModelProperty("选择状态1.待选择 2.已选择 3.已被他人选择 4.已签约 5.已拒绝 6.已失效")
    private Integer recommendStatus;

    @ApiModelProperty("铺位地址")
    private String address;

    @ApiModelProperty("是否可以上传租赁合同")
    private boolean canSubmitRentContract;


    public static List<PointRecommendPageVO> convertVO(List<PointRecommendDO> recommendList, List<PointInfoDO> pointList, Map<String, String> usernameMap, Map<Long, String> regionNameMap, List<Long> canSubmitRentContractShopIds) {
        if(CollectionUtils.isEmpty(recommendList) || CollectionUtils.isEmpty(pointList)){
            return Lists.newArrayList();
        }
        List<PointRecommendPageVO> resultList = new ArrayList<>();
        Map<Long, PointInfoDO> pointMap = pointList.stream().collect(Collectors.toMap(k -> k.getId(), Function.identity()));
        for (PointRecommendDO pointRecommend : recommendList) {
            PointRecommendPageVO recommend = new PointRecommendPageVO();
            recommend.setRecommendStatus(pointRecommend.getStatus());
            PointInfoDO pointInfo = pointMap.get(pointRecommend.getPointId());
            if(Objects.nonNull(pointInfo)){
                recommend.setPointId(pointInfo.getId());
                recommend.setPointName(pointInfo.getPointName());
                recommend.setPointCode(pointInfo.getPointCode());
                recommend.setRegionId(pointInfo.getRegionId());
                recommend.setRegionNodeName(regionNameMap.get(pointInfo.getRegionId()));
                recommend.setPointStatus(pointInfo.getPointStatus());
                if(PointStatusEnum.POINT_STATUS_4.getCode().equals(pointInfo.getPointStatus())){
                    recommend.setPointStatus(PointStatusEnum.POINT_STATUS_3.getCode());
                }
                recommend.setPointScore(pointInfo.getPointScore());
                recommend.setPointArea(pointInfo.getPointArea());
                recommend.setDevelopmentManagerUsername(usernameMap.get(pointInfo.getDevelopmentManager()));
                recommend.setDevelopmentTime(pointInfo.getDevelopmentTime());
                recommend.setAddress(pointInfo.getAddress());
                if(canSubmitRentContractShopIds.contains(pointInfo.getShopId())){
                    recommend.setCanSubmitRentContract(Boolean.TRUE);
                }
            }
            resultList.add(recommend);
        }
        return resultList;
    }

}
