package com.red.circle.other.app.inner.endpoint.team.bd;

import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.other.app.inner.service.team.BdTeamLeaderClientService;
import com.red.circle.other.inner.endpoint.team.bd.api.BdTeamLeaderClientApi;
import com.red.circle.other.inner.model.cmd.team.bd.BdTeamLeaderAddCmd;
import com.red.circle.other.inner.model.cmd.team.bd.BdTeamLeaderOpsPageQryCmd;
import com.red.circle.other.inner.model.dto.agency.bd.BdTeamInfoDTO;
import com.red.circle.other.inner.model.dto.agency.bd.BdTeamLeaderDTO;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * bd leader 团队.
 *
 * @author pengliang on 2023/11/21
 */
@Validated
@RestController
@RequestMapping(value = BdTeamLeaderClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class BdTeamLeaderClientEndpoint implements BdTeamLeaderClientApi {

  private final BdTeamLeaderClientService bdTeamLeaderClientService;

  @Override
  public ResultResponse<BdTeamLeaderDTO> getById(Long id) {
    return ResultResponse.success(bdTeamLeaderClientService.getById(id));
  }

  @Override
  public ResultResponse<BdTeamLeaderDTO> getByUserId(Long userId) {
    return ResultResponse.success(bdTeamLeaderClientService.getByUserId(userId));
  }

  @Override
  public ResultResponse<Long> countBdByLeaderUserId(Long leadUserId) {
    return ResultResponse.success(bdTeamLeaderClientService.countBdByLeaderUserId(leadUserId));
  }

  @Override
  public ResultResponse<List<BdTeamInfoDTO>> listByLeaderUserId(Long leadUserId, Long lastId) {
    return ResultResponse.success(bdTeamLeaderClientService.listByLeaderUserId(leadUserId, lastId));
  }

  @Override
  public ResultResponse<Void> add(BdTeamLeaderAddCmd cmd) {
    bdTeamLeaderClientService.add(cmd);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Boolean> check(Long userId) {
    return ResultResponse.success(
        bdTeamLeaderClientService.check(userId)
    );
  }

  @Override
  public ResultResponse<PageResult<BdTeamLeaderDTO>> pageOps(
      BdTeamLeaderOpsPageQryCmd qryCmd) {
    return ResultResponse.success(bdTeamLeaderClientService.pageOps(qryCmd));
  }

  @Override
  public ResultResponse<Map<Long, Long>> mapCountByLeadUserIds(Set<Long> bdLeadUserIds) {
    return ResultResponse.success(bdTeamLeaderClientService.mapCountByLeadUserIds(bdLeadUserIds));
  }

  @Override
  public ResultResponse<Void> updateSelectiveById(BdTeamLeaderDTO dto) {
    bdTeamLeaderClientService.updateLeaderSelectiveById(dto);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Map<Long, Long>> mapTeamBdUserId(Set<Long> Ids) {
    return ResultResponse.success(bdTeamLeaderClientService.mapTeamBdUserId(Ids));
  }

  @Override
  public ResultResponse<Void> removeLeader(Long teamId, Long bdLeadUserId) {
    bdTeamLeaderClientService.removeLeader(teamId, bdLeadUserId);
    return ResultResponse.success();
  }

}
