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.cmd.user.user.AccountBindUserAuthTypeCmd;
import com.red.circle.other.app.dto.cmd.user.user.BindUserAuthTypeCmd;
import com.red.circle.other.app.dto.cmd.user.user.UnBindUserAuthTypeCmd;
import com.red.circle.other.app.service.user.user.UserAuthTypeService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户认证信息服务.
 *
 * @author pengliang on 2021/5/11
 * @eo.api-type http
 * @eo.groupName 用户服务.认证信息
 * @eo.path /user/user-auth-type
 */
@RestController
@RequestMapping("/user/user-auth-type")
@RequiredArgsConstructor
public class UserAuthTypeRestController extends BaseController {

  private final UserAuthTypeService userAuthTypeService;

  /**
   * 已认证列表.
   *
   * @eo.name 已认证列表.
   * @eo.url
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping
  public List<String> listUserAuthType(AppExtCommand cmd) {
    return userAuthTypeService.listUserAuthType(cmd);
  }

  /**
   * 绑定认证关系.
   *
   * @eo.name 绑定认证关系.
   * @eo.url /bind
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/bind")
  public void bindUserAuthType(@RequestBody @Validated BindUserAuthTypeCmd cmd) {
    userAuthTypeService.bindUserAuthType(cmd);
  }


  /**
   * 解除绑定认证关系.
   *
   * @eo.name 解除绑定认证关系.
   * @eo.url /unbind
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/unbind")
  public void unBindUserAuthType(@RequestBody @Validated UnBindUserAuthTypeCmd cmd) {
    userAuthTypeService.unBindUserAuthType(cmd);
  }

  /**
   * 设置账号密码.
   */
  @PostMapping("/account-bind")
  public void accountBindUserAuthType(@RequestBody @Validated AccountBindUserAuthTypeCmd cmd) {
    userAuthTypeService.accountBindUserAuthType(cmd);
  }

  /**
   * 修改账号密码.
   */
  @PostMapping("/account-update")
  public void accountUpdate(@RequestBody @Validated AccountBindUserAuthTypeCmd cmd) {
    userAuthTypeService.accountUpdate(cmd);
  }

  /**
   * 账号是否已经绑定.
   *
   * @eo.name 账号绑定认证关系.
   * @eo.url /account-is-bind
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/account-is-bind")
  public Boolean accountIsBind(AppExtCommand cmd) {
    return userAuthTypeService.accountIsBind(cmd);
  }

  /**
   * 删除用户账号密码登录信息.
   */
  @GetMapping("/delete/account-auth/{userId}")
  public void deleteUserAccountLogin(@PathVariable("userId") Long userId) {
    userAuthTypeService.deleteUserAccountLogin(userId);
  }

}
