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


import com.red.circle.common.business.enums.ConsoleAccountStatusEnum;
import com.red.circle.console.app.dto.clienobject.user.UserIdentityCO;
import com.red.circle.console.app.dto.clienobject.user.UserProfileDetailCO;
import com.red.circle.console.app.dto.clienobject.user.UserProfileListCO;
import com.red.circle.console.app.dto.clienobject.user.UserVipEquityCO;
import com.red.circle.console.app.service.app.user.UserBaseInfoService;
import com.red.circle.console.infra.annotations.OpsOperationReqLog;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.tool.core.tuple.ImmutableKeyValuePair;
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.UserProfileUpdateCmd;
import com.red.circle.other.inner.model.dto.user.UserLatestDeviceAssociatedDTO;
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
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;

/**
 * <p>
 * 用户基本信息 前端控制器
 * </p>
 *
 * @author pengliang
 * @since 2019-11-08
 */
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/user/base/info", produces = MediaType.APPLICATION_JSON_VALUE)
public class UserBaseInfoRestController extends BaseController {

  private final UserBaseInfoService userBaseInfoService;

  /**
   * 用户分页列表.
   */
  @PostMapping("/page")
  public PageResult<UserProfileListCO> userLisPage(
      @RequestBody UserProfileListQryCmd query) {
    return userBaseInfoService.pageListQuery(query);
  }

  /**
   * 获取用户详情.
   */
  @GetMapping("/{userId}")
  public UserProfileDetailCO getUserId(@PathVariable Long userId) {
    return userBaseInfoService.getByUserId(userId);
  }

  /**
   * 获取用户详情.
   */
  @GetMapping("/account/{account}")
  public List<UserProfileDTO> getAccount(@PathVariable String account) {
    return userBaseInfoService.getByAccount(account);
  }

  @OpsOperationReqLog(value = "修改APP用户信息")
  @PutMapping
  public void updateUserInfo(@RequestBody UserProfileUpdateCmd param) {
    userBaseInfoService.updateUserProfile(param);
  }

  @OpsOperationReqLog(value = "修改ai视频用户信息")
  @PutMapping("/vest")
  public void updateVestUserInfo(@RequestBody UserBaseInfoCmd cmd) {

    userBaseInfoService.updateVestUserInfo(cmd);
  }

  /**
   * im签名获取.
   */
  @PostMapping("/im/sig")
  public ImmutableKeyValuePair<String, String> cleanLive(String phoneNumber, String password) {
    return userBaseInfoService.imUserLogin(phoneNumber, password);
  }

  @OpsOperationReqLog(value = "用户当前账号状态")
  @GetMapping("/account/status/{userId}")
  public ImmutableKeyValuePair<ConsoleAccountStatusEnum, String> updateAccountStatus(
      @PathVariable("userId") Long userId) {
    return userBaseInfoService.listAccountStatus(userId);
  }

  /**
   * 获取用户设备imei.
   */
  @GetMapping("/user/imei/{userId}")
  public String getUserImei(@PathVariable Long userId) {
    return userBaseInfoService.getImeiByUserId(userId);
  }

  /**
   * 获取用户最新版本号.
   */
  @GetMapping("/device/{userId}")
  public UserLatestDeviceAssociatedDTO getDeviceByUserId(@PathVariable Long userId) {
    return userBaseInfoService.getDeviceByUserId(userId);
  }

  /**
   * 用户身份信息.
   */
  @GetMapping("/{userId}/identity")
  public UserIdentityCO getUserIdentity(@PathVariable("userId") Long userId) {
    return userBaseInfoService.getUserIdentity(userId);
  }

  /**
   * 获得用户VIP权益.
   */
  @GetMapping("/user/vip/equity/{userId}")
  public UserVipEquityCO getUserVipEquityVO(@PathVariable Long userId) {
    return userBaseInfoService.getUserVipEquityCO(userId);
  }


}
