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

import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.external.inner.endpoint.message.TrtcClient;
import com.red.circle.framework.core.dto.PageCommand;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.other.domain.gateway.user.UserRunProfileTransportGateway;
import com.red.circle.other.domain.model.user.UserProfile;
import com.red.circle.other.inner.endpoint.team.agency.AgentTeamClient;
import com.red.circle.other.inner.endpoint.user.user.api.UserProfileClientApi;
import com.red.circle.other.inner.model.cmd.user.PhotoWallApprovalTableQryCmd;
import com.red.circle.other.inner.model.cmd.user.UpdateUserAvatarBatchCmd;
import com.red.circle.other.inner.model.cmd.user.UpdateUserNicknameBatchCmd;
import com.red.circle.other.inner.model.cmd.user.UserAccountQryCmd;
import com.red.circle.other.inner.model.cmd.user.UserBaseInfoCmd;
import com.red.circle.other.inner.model.cmd.user.UserProfileListQryCmd;
import com.red.circle.other.inner.model.cmd.user.UserRemoveUsePropsCmd;
import com.red.circle.other.inner.model.cmd.user.UserSwitchUsePropsCmd;
import com.red.circle.other.inner.model.dto.user.UserPhotoWallDTO;
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
import com.red.circle.other.inner.model.dto.user.UserRegisterInfoDTO;
import com.red.circle.other.inner.model.dto.user.UserRunProfileDTO;
import com.red.circle.other.app.inner.service.user.user.UserProfileClientService;
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/6/5
 */
@Validated
@RestController
@RequestMapping(value = UserProfileClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class UserProfileClientEndpoint implements UserProfileClientApi {

  private final AgentTeamClient agentTeamClient;
  private final UserProfileClientService userProfileClientService;
  private final UserRunProfileTransportGateway userRunProfileTransportGateway;
  private final TrtcClient trtcClient;

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

  @Override
  public ResultResponse<Void> removeCacheAll(Set<Long> userIds) {
    userProfileClientService.removeCacheAll(userIds);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> removeCache(Set<Long> userIds) {
    userProfileClientService.removeCache(userIds);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<String> getToken(Long userId,String roomId) {

    return trtcClient.createAgoraTokenGoUp(userId,roomId);
  }

  @Override
  public ResultResponse<Void> removeCache(Long userId) {
    userProfileClientService.removeCache(Set.of(userId));
    return ResultResponse.success();
  }

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

  @Override
  public ResultResponse<UserProfileDTO> getByAccount(String sysOrigin, String account) {
    return ResultResponse.success(userProfileClientService.getByAccount(sysOrigin, account));
  }


  @Override
  public ResultResponse<List<UserProfileDTO>> getByAccount(String account) {
    return ResultResponse.success(userProfileClientService.getByAccount(account));
  }


  @Override
  public ResultResponse<UserProfileDTO> getByAccountOne(String account) {
    return ResultResponse.success(userProfileClientService.getByAccountOne(account));
  }


  @Override
  public ResultResponse<PageResult<UserProfileDTO>> pageListQuery(UserProfileListQryCmd query) {
    return ResultResponse.success(userProfileClientService.pageListQuery(query));
  }

  @Override
  public ResultResponse<Map<Long, UserProfileDTO>> mapByUserIds(Set<Long> userIds) {
    return ResultResponse.success(userProfileClientService.mapByUserIds(userIds));
  }

  @Override
  public ResultResponse<List<UserProfileDTO>> listByUserId(Set<Long> userIds) {
    return ResultResponse.success(userProfileClientService.listByUserId(userIds));
  }

  @Override
  public ResultResponse<List<UserProfileDTO>> listByAccount(UserAccountQryCmd qryCmd) {
    return ResultResponse.success(
        userProfileClientService.listByAccount(qryCmd.getSysOrigin(), qryCmd.getAccounts()));
  }

  @Override
  public ResultResponse<String> getLanguage(Long userId) {
    return ResultResponse.success(userProfileClientService.getLanguage(userId));
  }

  @Override
  public ResultResponse<Map<Long, String>> mapLanguage(Set<Long> userIds) {
    return ResultResponse.success(userProfileClientService.mapLanguage(userIds));
  }

  @Override
  public ResultResponse<SysOriginPlatformEnum> getSysOrigin(Long userId) {
    return ResultResponse.success(
        SysOriginPlatformEnum.toEnum(userProfileClientService.getSysOrigin(userId)));
  }

  @Override
  public ResultResponse<Void> switchUseProps(UserSwitchUsePropsCmd cmd) {
    userProfileClientService.switchUseProps(cmd.getUserId(), cmd.getPropsId());
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> removeUseProps(UserRemoveUsePropsCmd cmd) {
    userProfileClientService.removeUseProps(cmd.getUserId(), cmd.getPropsType());
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<List<String>> listUserPropsVipActualEquity(Long userId) {
    return ResultResponse.success(userProfileClientService.listUserPropsVipActualEquity(userId));
  }

  @Override
  public ResultResponse<Void> updateUserAvatar(Long id, String avatar) {
    userProfileClientService.updateUserAvatar(id, avatar);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> updateUserAvatarBatch(UpdateUserAvatarBatchCmd cmd) {
    userProfileClientService.updateUserAvatarBatch(cmd);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> updateUserNicknameBatch(List<UpdateUserNicknameBatchCmd> cmd) {
    userProfileClientService.updateUserNicknameBatch(cmd);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> updateBatchUserAutographEmpty(Collection<Long> ids) {
    userProfileClientService.updateBatchUserAutographEmpty(ids);
    return ResultResponse.success();
  }

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

  @Override
  public ResultResponse<Map<Long, UserRegisterInfoDTO>> mapRegisterInfo(Set<Long> userIds) {
    return ResultResponse.success(userProfileClientService.mapRegisterInfo(userIds));
  }

  @Override
  public ResultResponse<UserRegisterInfoDTO> getRegisterInfo(Long userId) {
    return ResultResponse.success(userProfileClientService.getRegisterInfo(userId));
  }


  @Override
  public ResultResponse<UserRunProfileDTO> getRunProfileById(Long id) {
    return ResultResponse.success(userProfileClientService.getRunProfileById(id));
  }

  @Override
  public ResultResponse<Void> updateRunProfileById(Long id, String accountStatus) {
    userRunProfileTransportGateway.updateUserRunProfile(id, accountStatus);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> removeRunProfileById(Long id) {
    userProfileClientService.removeRunProfileById(id);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> updateSelectiveById(UserBaseInfoCmd cmd) {
    userProfileClientService.updateSelectiveById(cmd);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> restoreDelById(Long id) {
    userProfileClientService.restoreDelById(id);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> deletePhotoWall(Long id) {
    userProfileClientService.deletePhotoWall(id);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<PageResult<UserPhotoWallDTO>> pageUserPhotoWall(PageCommand command) {
    return ResultResponse.success(userProfileClientService.pageUserPhotoWall(command));
  }

  @Override
  public ResultResponse<List<UserPhotoWallDTO>> listUserPhotoWall(Long userId) {
    return ResultResponse.success(userProfileClientService.listUserPhotoWall(userId));
  }

  @Override
  public ResultResponse<UserPhotoWallDTO> userPhotoWall(Long id) {
    return ResultResponse.success(userProfileClientService.userPhotoWall(id));
  }

  @Override
  public ResultResponse<List<UserPhotoWallDTO>> listUserPhotoWallNormal(Long userId) {
    return ResultResponse.success(userProfileClientService.listUserPhotoWallNormal(userId));
  }

  @Override
  public ResultResponse<PageResult<UserPhotoWallDTO>> pageUserDetailsPhotoWall(
      PhotoWallApprovalTableQryCmd cmd) {
    return ResultResponse.success(userProfileClientService.pageUserDetailsPhotoWall(cmd));
  }

  @Override
  public ResultResponse<List<UserProfileDTO>> listRandomVest(int size) {
    return ResultResponse.success(userProfileClientService.listRandomVest(size));
  }

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