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


import com.red.circle.common.business.dto.cmd.PageUserIdCmd;
import com.red.circle.common.business.dto.cmd.UserIdCmd;
import com.red.circle.console.app.dto.clienobject.sys.SysImAccountCO;
import com.red.circle.console.app.service.app.sys.SysImAccountService;
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.other.inner.model.cmd.sys.SysImAccountCmd;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
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>
 * im账号管理 前端控制器
 * </p>
 *
 * @author houyong
 * @since 2020-06-09
 */
@RestController
@RequestMapping("/sys/im/account")
@RequiredArgsConstructor
public class SysImAccountRestController extends BaseController {

  private final SysImAccountService sysImAccountService;

  /**
   * 分页列表.
   */
  @GetMapping(value = "/page")
  public PageResult<SysImAccountCO> page(PageUserIdCmd cmd) {
    return sysImAccountService.pageImAccountVo(cmd);
  }

  @OpsOperationReqLog(value = "添加im登录账号")
  @PostMapping
  public void add(@RequestBody SysImAccountCmd sysImAccount) {
    sysImAccount.setCreateUser(sysImAccount.getReqUserId());
    sysImAccount.setUpdateUser(sysImAccount.getReqUserId());
    sysImAccountService.addImAccount(sysImAccount);
  }

  @OpsOperationReqLog(value = "重置IM密码")
  @PutMapping("/reset")
  public void reset(UserIdCmd cmd) {
    sysImAccountService.resetPassword(cmd.getUserId(), cmd.getReqUserId());
  }

  @OpsOperationReqLog(value = "删除IM用户")
  @DeleteMapping
  public void delete(Long userId) {
    sysImAccountService.deleteImAccount(userId);
  }
}
