package com.cool.store.vo.shop;

import cn.hutool.core.date.DateUtil;
import com.cool.store.entity.LineAuditInfoDO;
import com.cool.store.entity.ShopAuditInfoDO;
import com.cool.store.entity.ShopStageInfoDO;
import com.cool.store.enums.point.ShopStageEnum;
import com.cool.store.enums.point.ShopSubStageEnum;
import com.cool.store.enums.point.ShopSubStageStatusEnum;
import com.cool.store.utils.CoolDateUtils;
import com.cool.store.vo.AuditInfoVO;
import com.cool.store.vo.LineAuditInfoVO;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;

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



/**
 * @author zhangchenbiao
 * @FileName: ShopStageInfoVO
 * @Description:
 * @date 2024-04-11 17:10
 */
@Data
@Slf4j
public class ShopStageInfoVO {

    @ApiModelProperty("店铺阶段")
    private Integer shopStage;

    @ApiModelProperty("店铺子阶段")
    private Integer shopSubStage;

    @ApiModelProperty("店铺阶段状态")
    private Integer shopSubStageStatus;

    @ApiModelProperty("当前阶段是否结束 0未结束  1已结束")
    private Boolean isTerminated;

    @ApiModelProperty("预估完成时间")
    private String planCompleteTime;

    @ApiModelProperty("实际完成时间")
    private String actualCompleteTime;

    @ApiModelProperty("阶段审核信息")
    private AuditInfoVO auditInfo;

    public ShopStageInfoVO(Integer shopStage, Integer shopSubStage, Integer shopSubStageStatus, Boolean isTerminated) {
        this.shopStage = shopStage;
        this.shopSubStage = shopSubStage;
        this.shopSubStageStatus = shopSubStageStatus;
        this.isTerminated = isTerminated;

    }

    public static List<ShopStageInfoVO> convertList(List<ShopStageInfoDO> stageList, List<ShopAuditInfoDO> auditList){
        if(CollectionUtils.isEmpty(stageList)){
            return Lists.newArrayList();
        }
        Map<Long, ShopAuditInfoDO> auditMap = auditList.stream().collect(Collectors.toMap(ShopAuditInfoDO::getId, Function.identity()));
        List<ShopStageInfoVO> resultList = new ArrayList<>();
        for (ShopStageInfoDO stageInfo : stageList) {
            ShopStageInfoVO shopStageInfo = new ShopStageInfoVO(stageInfo.getShopStage(), stageInfo.getShopSubStage(), stageInfo.getShopSubStageStatus(), stageInfo.getIsTerminated());
            ShopAuditInfoDO auditInfo = auditMap.get(stageInfo.getAuditId());
            AuditInfoVO auditInfoVO = AuditInfoVO.convertVO(auditInfo);
            shopStageInfo.setAuditInfo(auditInfoVO);
            shopStageInfo.setPlanCompleteTime(stageInfo.getPlanCompleteTime());
            shopStageInfo.setActualCompleteTime(CoolDateUtils.parseStrToStr(CoolDateUtils.DATE_FORMAT_SEC,CoolDateUtils.DATE_FORMAT_SEC1,stageInfo.getActualCompleteTime()));
            resultList.add(shopStageInfo);
        }
        return resultList;
    }

}
