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

import com.red.circle.console.app.service.app.sys.SysAdministratorService;
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.AddSysAdministratorCmd;
import com.red.circle.other.inner.model.cmd.sys.AppUserDetailsQryCmd;
import com.red.circle.other.inner.model.cmd.sys.SysAdministratorChangeStatusCmd;
import com.red.circle.other.inner.model.dto.sys.SysAdministratorInfoDTO;
import lombok.RequiredArgsConstructor;
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;

/**
 * APP管理员表 前端控制器.
 *
 * @author houyong
 * @since 2021-03-23
 */
@RestController
@RequestMapping("/sys/administrator")
@RequiredArgsConstructor
public class SysAdministratorRestController extends BaseController {

  private final SysAdministratorService sysAdministratorService;

  /**
   * APP管理员分页列表.
   */
  @GetMapping("/page")
  public PageResult<SysAdministratorInfoDTO> pageManager(
      AppUserDetailsQryCmd appUserDetailsQuery) {
    return sysAdministratorService.pageUserDetails(appUserDetailsQuery);
  }

  /**
   * 添加APP管理员.
   */
  @PostMapping("/add")
  public void addSysAdministrator(@RequestBody AddSysAdministratorCmd cmd) {
    sysAdministratorService.addSysAdministrator(cmd);
  }

  @OpsOperationReqLog("删除APP管理员")
  @GetMapping("/delete/{id}")
  public void deleteSysAdministrator(@PathVariable("id") Long id) {
    sysAdministratorService.deleteSysAdministrator(id);
  }

  @OpsOperationReqLog("变更角色")
  @GetMapping("/change_roles/{id}/{roles}")
  public void changeRoles(@PathVariable("id") Long id,
      @PathVariable("roles") String roles) {
    sysAdministratorService.changeRoles(id, roles);
  }

  /**
   * 禁用/启用APP管理员.
   */
  @OpsOperationReqLog(value = "禁用/启用APP管理员")
  @PutMapping
  public void changeStatusAdministrator(
      @RequestBody SysAdministratorChangeStatusCmd param) {
    sysAdministratorService.changeStatusAdministrator(param);
  }

}
