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

import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.other.app.inner.service.live.RoomManagerClientService;
import com.red.circle.other.inner.endpoint.live.api.RoomManagerClientApi;
import com.red.circle.other.inner.model.cmd.room.RoomProfileOpsQryCmd;
import com.red.circle.other.inner.model.dto.live.RoomCounterDTO;
import com.red.circle.other.inner.model.dto.live.RoomProfileDTO;
import com.red.circle.other.inner.model.dto.live.RoomProfileManagerDTO;
import com.red.circle.wallet.inner.endpoint.wallet.WalletGoldClient;
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/31
 */
@Validated
@RestController
@RequestMapping(value = RoomManagerClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class RoomManagerClientEndpoint implements RoomManagerClientApi {

  private final WalletGoldClient walletGoldClient;
  private final RoomManagerClientService roomManagerClientService;

  @Override
  public ResultResponse<Void> updateUserLangCode(Long userId, String langCode) {
    roomManagerClientService.updateUserLangCode(userId, langCode);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Long> getUserRoomId(Long userId) {
    return ResultResponse.success(roomManagerClientService.getUserRoomId(userId));
  }

  @Override
  public ResultResponse<Void> updateRoomSettingMemberCapacity(Long userId, Integer maxMember,
      Integer adminNumber) {
    roomManagerClientService.updateRoomSettingMemberCapacity(userId, maxMember, adminNumber);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<RoomProfileDTO> getProfileById(Long roomId) {
    return ResultResponse.success(roomManagerClientService.getProfileById(roomId));
  }

  @Override
  public ResultResponse<RoomProfileManagerDTO> getRoomProfileManagerById(Long roomId) {
    return ResultResponse.success(roomManagerClientService.getRoomProfileManagerById(roomId));
  }

  @Override
  public ResultResponse<RoomProfileDTO> getById(Long roomId) {
    return ResultResponse.success(roomManagerClientService.getById(roomId));
  }

  @Override
  public ResultResponse<List<RoomProfileDTO>> listByIds(Set<Long> userIds) {
    return ResultResponse.success(roomManagerClientService.listProfileByIds(userIds));
  }

  @Override
  public ResultResponse<RoomCounterDTO> getRoomCounterByUserId(Long userId) {
    return ResultResponse.success(roomManagerClientService.getRoomCounterByUserId(userId));
  }

  @Override
  public ResultResponse<RoomProfileDTO> getProfileByUserId(Long userId) {
    return ResultResponse.success(roomManagerClientService.getProfileByUserId(userId));
  }

  @Override
  public ResultResponse<Map<Long, RoomProfileDTO>> mapProfileByRoomIds(Set<Long> roomIds) {
    return ResultResponse.success(roomManagerClientService.mapProfileByRoomIds(roomIds));
  }

  @Override
  public ResultResponse<Map<Long, RoomProfileDTO>> mapProfileByUserIds(Set<Long> userIds) {
    return ResultResponse.success(roomManagerClientService.mapProfileByUserIds(userIds));
  }

  @Override
  public ResultResponse<Void> updateUserCountry(Long userId, String countryCode,
      String countryName) {
    roomManagerClientService.updateUserCountry(userId, countryCode, countryName);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<List<RoomProfileManagerDTO>> listOps(RoomProfileOpsQryCmd qryCmd) {
    return ResultResponse.success(roomManagerClientService.listOps(qryCmd));
  }

  @Override
  public ResultResponse<Boolean> updateSelectiveProfile(RoomProfileDTO roomProfile) {
    return ResultResponse.success(roomManagerClientService.updateSelectiveProfile(roomProfile));
  }

  @Override
  public ResultResponse<Void> removeCacheUserRole(Long userId, Long roomId) {
    roomManagerClientService.removeCacheUserRole(userId, roomId);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> incrCounterAdmin(Long roomId) {
    roomManagerClientService.incrCounterAdmin(roomId);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> incrCounterMember(Long roomId) {
    roomManagerClientService.incrCounterMember(roomId);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> decrCounterAdmin(Long roomId) {
    roomManagerClientService.decrCounterAdmin(roomId);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> decrCounterMember(Long roomId) {
    roomManagerClientService.decrCounterMember(roomId);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Boolean> checkOwn(Long roomId, Long userId) {
    return ResultResponse.success(roomManagerClientService.checkOwn(roomId, userId));
  }

  @Override
  public ResultResponse<Void> test() {
    walletGoldClient.getBalance(1L);
    return ResultResponse.success();
  }

}
