package com.red.circle.other.adapter.app.user.user;

import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.app.dto.clientobject.user.user.UserProfileCardCO;
import com.red.circle.other.app.dto.clientobject.user.user.UserProfileUsePropsCO;
import com.red.circle.other.app.dto.cmd.user.user.AccountQryCmd;
import com.red.circle.other.app.dto.cmd.user.user.UserCardQryCmd;
import com.red.circle.other.app.dto.cmd.user.user.UserProfileModifyCmd;
import com.red.circle.other.app.dto.cmd.user.user.UserProfileQryCmd;
import com.red.circle.other.app.service.user.user.UserProfileService;
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户资料管理.
 *
 * @author pengliang on 2020/9/14
 * @eo.api-type http
 * @eo.groupName 用户服务.用户资料
 * @eo.path /user/user-profile
 */
@RestController
@RequestMapping(value = "/user/user-profile", produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class UserProfileRestController extends BaseController {

  private final UserProfileService userProfileService;

  /**
   * 获取用户基本信息.
   *
   * @eo.name 获取用户基本信息.
   * @eo.url
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping
  public UserProfileDTO getProfile(UserProfileQryCmd cmd) {
    return userProfileService.getUserProfile(cmd);
  }

  /**
   * 获取用户基本信息.
   *
   * @eo.name 获取用户基本信息.
   * @eo.url /user-id
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/user-id")
  public UserProfileDTO getProfileByUserId(UserProfileQryCmd cmd) {
    cmd.setUserId(cmd.getReqUserId());
    return userProfileService.getUserProfile(cmd);
  }


  /**
   * 获取用户基本信息（带使用道具）.
   *
   * @eo.name 获取用户基本信息（带使用道具）.
   * @eo.url /use-props
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/use-props")
  public UserProfileUsePropsCO getPropsUserProfile(UserProfileQryCmd cmd) {
    return userProfileService.getPropsUserProfile(cmd);
  }

  /**
   * 用户账号搜索.
   * <p>首页用户搜索</p>
   *
   * @eo.name 用户账号搜索.<p>首页用户搜索</p>
   * @eo.url /search
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/search")
  public UserProfileDTO getProfile(AccountQryCmd cmd) {
    return userProfileService.getUserProfile(cmd);
  }

    /**
     * 账号搜索开放接口
     */
    @GetMapping("/open-search")
    public UserProfileDTO openSearch(AccountQryCmd cmd) {
        return userProfileService.getUserOpenProfile(cmd);
    }

  /**
   * @eo.name 获取用户卡片: 用于资料卡片查询，不同系统之间不允许访问
   * @eo.url /card
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/card")
  public UserProfileCardCO getProfileCard(UserCardQryCmd cmd) {
    return userProfileService.getUserProfileCard(cmd);
  }

  /**
   * 修改资料.
   *
   * @eo.name 修改资料.
   * @eo.url /update
   * @eo.method put
   * @eo.request-type json
   */
  @PutMapping("/update")
  public UserProfileDTO updateUserProfile(@RequestBody @Validated UserProfileModifyCmd cmd) {
    return userProfileService.updateUserProfile(cmd);
  }

  /**
   * 是否允许使用语音房业务(需要验证系统:YOLO).
   *
   * @eo.url /check/voice/room/auth
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/check/voice/room/auth")
  public Boolean checkVoiceRoomAuth(AppExtCommand cmd) {
    return userProfileService.checkVoiceRoomAuth(cmd);
  }

}
