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

import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.other.inner.endpoint.live.RoomManagerClient;
import com.red.circle.other.app.inner.service.team.AgentTeamClientService;
import com.red.circle.other.inner.endpoint.team.agency.api.AgentTeamClientApi;
import com.red.circle.other.inner.model.dto.agency.agency.TeamExchangeSurplusTargetDTO;
import com.red.circle.other.inner.model.dto.agency.agency.TeamMemberDTO;
import com.red.circle.other.inner.model.dto.agency.agency.TeamProfileDTO;
import com.red.circle.other.inner.model.dto.agency.agency.UserTeamRegionDTO;
import java.util.Collection;
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;

/**
 * 代理团队服务.
 *
 * @author pengliang on 2023/5/26
 */
@Validated
@RestController
@RequestMapping(value = AgentTeamClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class AgentTeamClientEndpoint implements AgentTeamClientApi {

  private final RoomManagerClient roomManagerClient;
  private final AgentTeamClientService agentTeamClientService;

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

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

  @Override
  public ResultResponse<Void> refreshActiveTime(Long userId) {
    agentTeamClientService.refreshActiveTime(userId);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<TeamMemberDTO> getByMemberId(Long memberId) {
    return ResultResponse.success(agentTeamClientService.getByMemberId(memberId));
  }

  @Override
  public ResultResponse<Map<Long, TeamMemberDTO>> mapByMemberIds(Collection<Long> memberIds) {
    return ResultResponse.success(agentTeamClientService.mapByMemberIds(memberIds));
  }

  @Override
  public ResultResponse<Map<Long, TeamProfileDTO>> mapProfileByProfileIds(Set<Long> ids) {
    return ResultResponse.success(agentTeamClientService.mapProfileByIds(ids));
  }

  @Override
  public ResultResponse<TeamProfileDTO> getProfileByOwnUserId(Long ownUserId) {
    return ResultResponse.success(agentTeamClientService.getProfileByOwnUserId(ownUserId));
  }

  @Override
  public ResultResponse<TeamProfileDTO> getProfileByMemberId(Long memberId) {
    return ResultResponse.success(agentTeamClientService.getProfileByMemberId(memberId));
  }

  @Override
  public ResultResponse<List<UserTeamRegionDTO>> listUserTeamRegion(Set<Long> userIds) {
    return ResultResponse.success(agentTeamClientService.listUserTeamRegion(userIds));
  }

  @Override
  public ResultResponse<TeamProfileDTO> getProfileById(Long id) {
    return ResultResponse.success(agentTeamClientService.getProfileById(id));
  }

  @Override
  public ResultResponse<List<Long>> listMemberIds(Set<Long> userIds) {
    return ResultResponse.success(agentTeamClientService.listMemberIds(userIds));
  }

  @Override
  public ResultResponse<Void> test() {
    roomManagerClient.test();
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<List<TeamExchangeSurplusTargetDTO>> listByCondition(Long lastId,
      Long userId,
      String sysOrigin,
      Integer dateNumber) {
    return ResultResponse.success(
        agentTeamClientService.listByCondition(lastId, userId, sysOrigin, dateNumber));
  }

  @Override
  public ResultResponse<String> getTotalAmountUsd(Long userId, String sysOrigin,
      Integer dateNumber) {
    return ResultResponse.success(
        agentTeamClientService.getTotalAmountUsd(userId, sysOrigin, dateNumber));
  }
}
