package com.cool.store.dao.decoration;

import com.aliyun.openservices.shade.com.google.common.collect.Maps;
import com.cool.store.dto.decoration.TeamAreaMappingDTO;
import com.cool.store.entity.decoration.TeamAreaMappingDO;
import com.cool.store.mapper.decoration.TeamAreaMappingMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author suzhuhong
 * @Date 2025/10/29 15:08
 * @Version 1.0
 */
@Repository
public class TeamAreaMappingDAO {

    @Resource
    private TeamAreaMappingMapper teamAreaMappingMapper;

    public void batchInsert(Long teamId,List<Long> cityId){
        if (teamId == null || CollectionUtils.isEmpty(cityId)){
            return;
        }
        List<TeamAreaMappingDO> list = new ArrayList<>();
        cityId.forEach(x->{
            TeamAreaMappingDO teamAreaMappingDO = new TeamAreaMappingDO();
            teamAreaMappingDO.setTeamId(teamId);
            teamAreaMappingDO.setOpenCityId(x);
            list.add(teamAreaMappingDO);
        });
        teamAreaMappingMapper.batchInsert(list);
    }

    public int deletedByTeamId(Long teamId){
        if (teamId == null){
            return 0;
        }
        return teamAreaMappingMapper.deletedByTeamId(teamId);
    }

    public int deletedIds(List<Long> ids){
        if (CollectionUtils.isEmpty(ids)){
            return 0;
        }
        return teamAreaMappingMapper.deletedIds(ids);
    }

    public TeamAreaMappingDO getByCityId(Long cityId){
        return teamAreaMappingMapper.getByCityId(cityId);
    }


    public Map<Long, List<TeamAreaMappingDTO>> listByTeamIdList(List<Long> teamIdList){
        if (CollectionUtils.isEmpty(teamIdList)){
            return Maps.newHashMap();
        }
        List<TeamAreaMappingDTO> teamAreaMappingDTOS = teamAreaMappingMapper.listByTeamIdList(teamIdList);
        Map<Long, List<TeamAreaMappingDTO>> map = teamAreaMappingDTOS.stream().collect(Collectors.groupingBy(TeamAreaMappingDTO::getTeamId));
        return map;
    }




}
