package com.tashow.cloud.systemapi.api.dept;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import com.tashow.cloud.common.pojo.CommonResult;
import com.tashow.cloud.common.util.collection.CollectionUtils;
import com.tashow.cloud.systemapi.api.dept.dto.PostRespDTO;
import com.tashow.cloud.systemapi.enums.ApiConstants;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(name = ApiConstants.NAME) // TODO 芋艿：fallbackFactory =
/** RPC 服务 - 岗位 */
public interface PostApi {

  String PREFIX = ApiConstants.PREFIX + "/post";

  @GetMapping(PREFIX + "/valid")
  /** 校验岗位是否合法 */
  CommonResult<Boolean> validPostList(@RequestParam("ids") Collection<Long> ids);

  @GetMapping(PREFIX + "/list")
  /** 获得岗位列表 */
  CommonResult<List<PostRespDTO>> getPostList(@RequestParam("ids") Collection<Long> ids);

  default Map<Long, PostRespDTO> getPostMap(Collection<Long> ids) {
    if (CollUtil.isEmpty(ids)) {
      return MapUtil.empty();
    }

    List<PostRespDTO> list = getPostList(ids).getData();
    return CollectionUtils.convertMap(list, PostRespDTO::getId);
  }
}
