package com.bonus.core.allocation.flow.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.core.allocation.flow.mapper.FlowDefinitionAreaMapper;
import com.bonus.core.allocation.flow.model.FlowDefinitionArea;
import com.bonus.core.allocation.flow.service.FlowDefinitionAreaService;
import com.bonus.core.autth.api.MgrAuthApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.invoke.SerializedLambda;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class FlowDefinitionAreaServiceImpl extends ServiceImpl<FlowDefinitionAreaMapper, FlowDefinitionArea> implements FlowDefinitionAreaService {
   @Autowired
   private MgrAuthApi mgrAuthApi;

//   public void saveDefinitionArea(Long definitionId, Long areaId) {
//      this.deleteDefinitionArea(definitionId);
//      FlowDefinitionArea flowDefinitionArea = new FlowDefinitionArea();
//      flowDefinitionArea.setDefinitionId(definitionId);
//      flowDefinitionArea.setAreaId(areaId);
//      ((FlowDefinitionAreaMapper)this.baseMapper).insert(flowDefinitionArea);
//   }
//
//   public void deleteDefinitionArea(Long definitionId) {
//      ((FlowDefinitionAreaMapper)this.baseMapper).delete((Wrapper)Wrappers.lambdaQuery().eq(FlowDefinitionArea::getDefinitionId, definitionId));
//   }

   public Map<Long, Long> queryDefinitionArea(List<Long> definitionIds) {
      return this.baseMapper.selectList(Wrappers.lambdaQuery(FlowDefinitionArea.class)
              .in(FlowDefinitionArea::getDefinitionId, definitionIds)).stream().filter((item) -> {
         return ObjectUtil.isNotNull(item.getAreaId());
      }).collect(Collectors.toMap(FlowDefinitionArea::getDefinitionId, FlowDefinitionArea::getAreaId));
   }

//   public List<Long> queryAuthDefinition(QueryDefinitionDto content) {
//      MgrUserAuthPO authPO = this.mgrAuthApi.getUserAuthPO();
//      return ((FlowDefinitionAreaMapper)this.baseMapper).queryAuthDefinition(content, authPO);
//   }
}
