package com.cool.store.vo.inspection.setting;

import com.cool.store.entity.HyInspectionSettingDO;
import com.cool.store.entity.HyInspectionSettingMappingDO;
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: InspectionSettingPageVO
 * @Description:
 * @date 2023-07-17 14:32
 */
@Data
public class InspectionSettingCheckVO {

    @ApiModelProperty("区域名称")
    private String zoneName;

    @ApiModelProperty("省市区")
    private String areaName;

    @ApiModelProperty("稽核人名称")
    private String inspectionUsername;

    public static List<InspectionSettingCheckVO> convertVO(List<HyInspectionSettingMappingDO> conflictInspectionSetting, List<HyInspectionSettingDO> inspectionSettingList, Map<String, String> userNameMap, Map<Long, String> areaNameMap){
        if(CollectionUtils.isEmpty(conflictInspectionSetting) || CollectionUtils.isEmpty(inspectionSettingList)){
            return Lists.newArrayList();
        }
        Map<Long, HyInspectionSettingDO> inspectionSettingMap = inspectionSettingList.stream().collect(Collectors.toMap(k -> k.getId(), Function.identity()));
        List<InspectionSettingCheckVO> resultList = new ArrayList<>();
        for (HyInspectionSettingMappingDO hyInspectionSettingMapping : conflictInspectionSetting) {
            HyInspectionSettingDO inspectionSetting = inspectionSettingMap.get(hyInspectionSettingMapping.getInspectionSettingId());
            if(Objects.isNull(inspectionSetting)){
                continue;
            }
            InspectionSettingCheckVO inspectionSettingCheck = new InspectionSettingCheckVO();
            inspectionSettingCheck.setInspectionUsername(userNameMap.get(inspectionSetting.getInspectionUserId()));
            inspectionSettingCheck.setZoneName(inspectionSetting.getZoneName());
            inspectionSettingCheck.setAreaName(areaNameMap.get(hyInspectionSettingMapping.getOpenAreaMappingId()));
            resultList.add(inspectionSettingCheck);
        }
        return resultList;
    }

}
