package com.cool.store.vo.shop;

import com.cool.store.dto.Preparation.ScheduleDTO;
import com.cool.store.entity.EnterpriseUserDO;
import com.cool.store.entity.ShopInfoDO;
import com.cool.store.entity.ShopStageInfoDO;
import com.cool.store.enums.FranchiseBrandEnum;
import com.cool.store.enums.JoinModeEnum;
import com.cool.store.enums.point.ShopSubStageStatusEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.*;

/**
 * @author zhangchenbiao
 * @FileName: MiniHomePageShopVO
 * @Description:
 * @date 2024-04-11 16:50
 */
@Data
public class MiniShopPageVO {

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

    @ApiModelProperty("店铺名称")
    private String shopName;

    @ApiModelProperty("店铺编码")
    private String shopCode;

    @ApiModelProperty("加盟合同签约完成标识，0-未完成，1-完成")
    private Boolean flag;

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

    @ApiModelProperty("门店所属区域id")
    private Long regionId;
    @ApiModelProperty("门店所属区域name")
    private String regionName;
    @ApiModelProperty("督导name")
    private String investmentName;
    @ApiModelProperty("督导userId")
    private String investmentUserId;

    @ApiModelProperty("预估完成时间")
    private Date planCompletionTime;

    @ApiModelProperty("总项数")
    private Integer totalColumn;

    @ApiModelProperty("完成项")
    private Integer completionColumn;

    @ApiModelProperty("所属品牌")
    private String franchiseBrand;
    @ApiModelProperty("加盟模式")
    private String joinMode;
    @ApiModelProperty("意向开店区域")
    private String wantRegionName;
    @ApiModelProperty("门店状态'0.跟进中 1.已完成 2.已放弃',")
    private Integer shopStatus;

    @ApiModelProperty("所属管理区域id")
    private Long managerRegionId;

    @ApiModelProperty("所属管理区域name")
    private String managerRegionName;

    public MiniShopPageVO(Long shopId, String shopName, String shopCode, Boolean flag, Long pointId, Long regionId, String regionName) {
        this.shopId = shopId;
        this.shopName = shopName;
        this.shopCode = shopCode;
        this.flag = flag;
        this.pointId = pointId;
        this.regionId = regionId;
        this.regionName = regionName;
    }

    public static List<MiniShopPageVO> convertList(List<ShopInfoDO> shopInfoList, Map<Long, ShopStageInfoDO> stageMap, Map<Long, String> regionNameMap, Map<Long, ScheduleDTO> scheduleMap, Map<Long, String> wantRegionMap, Map<String, EnterpriseUserDO> userInfoMap) {
        List<MiniShopPageVO> resultList = new ArrayList<>();
        for (ShopInfoDO shopInfo : shopInfoList) {
            ShopStageInfoDO stageInfoDO = stageMap.get(shopInfo.getId());
            Boolean flag = Boolean.FALSE;
            if (Objects.nonNull(stageInfoDO)) {
                if (ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_84.getShopSubStageStatus().equals(stageInfoDO.getShopSubStageStatus())) {
                    flag = Boolean.TRUE;
                }
            }
            if (Objects.isNull(regionNameMap)) {
                regionNameMap = new HashMap<>();
            }
            MiniShopPageVO miniShopPageVO = new MiniShopPageVO(shopInfo.getId(), shopInfo.getShopName(), shopInfo.getShopCode(), flag, shopInfo.getPointId(), shopInfo.getRegionId(), regionNameMap.getOrDefault(shopInfo.getRegionId(), ""));
            miniShopPageVO.setInvestmentUserId(shopInfo.getInvestmentManager());
            if (userInfoMap!=null){
                miniShopPageVO.setInvestmentName(userInfoMap.getOrDefault(shopInfo.getInvestmentManager(),new EnterpriseUserDO()).getName());
            }
            if (scheduleMap != null) {
                miniShopPageVO.setTotalColumn(scheduleMap.getOrDefault(shopInfo.getId(),new ScheduleDTO()).getTotalColumn());
                miniShopPageVO.setCompletionColumn(scheduleMap.getOrDefault(shopInfo.getId(),new ScheduleDTO()).getCompletionColumn());
                miniShopPageVO.setPlanCompletionTime(scheduleMap.getOrDefault(shopInfo.getId(),new ScheduleDTO()).getPlanCompleteTime());
            }
            miniShopPageVO.setFranchiseBrand(shopInfo.getFranchiseBrand());
            miniShopPageVO.setJoinMode(JoinModeEnum.getByCode(shopInfo.getJoinMode()));
            if (Objects.nonNull(wantRegionMap)) {
                miniShopPageVO.setWantRegionName(wantRegionMap.get(shopInfo.getWantShopAreaId()));
            }
            miniShopPageVO.setShopStatus(shopInfo.getShopStatus());
            miniShopPageVO.setManagerRegionId(shopInfo.getManagerRegionId());
            miniShopPageVO.setManagerRegionName(regionNameMap.getOrDefault(shopInfo.getManagerRegionId(), ""));
            resultList.add(miniShopPageVO);

        }
        return resultList;
    }

}
