package com.red.circle.console.adapter.app.team.manager;

import com.red.circle.console.app.dto.clienobject.team.manager.TeamManagerCO;
import com.red.circle.console.app.dto.cmd.app.team.manager.TeamManagerAddCmd;
import com.red.circle.console.app.dto.cmd.app.team.manager.TeamManagerUpdateCmd;
import com.red.circle.console.app.service.app.team.manager.TeamManagerService;
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.team.manager.TeamManagerOpsPageQryCmd;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 团队经理前端控制器.
 */
@RestController("teamOpsManagerRestController")
@RequiredArgsConstructor
@RequestMapping("/team/manager")
public class TeamManagerRestController extends BaseController {

  private final TeamManagerService teamManagerService;

  @GetMapping("/page")
  public PageResult<TeamManagerCO> pageOps(TeamManagerOpsPageQryCmd qryCmd) {
    return teamManagerService.pageOps(qryCmd);
  }

  @OpsOperationReqLog("添加团队经理")
  @PostMapping("/add")
  public void add(@RequestBody @Validated TeamManagerAddCmd cmd) {
    cmd.setCreateUser(getReqUserId());
    teamManagerService.add(cmd);
  }

  @OpsOperationReqLog("编辑团队经理")
  @PostMapping("/update")
  public void update(@RequestBody @Validated TeamManagerUpdateCmd cmd) {
    cmd.setUpdateUser(getReqUserId());
    teamManagerService.update(cmd);
  }

  @OpsOperationReqLog("删除团队经理")
  @GetMapping("/del")
  public void deleteById(Long id) {
    teamManagerService.delete(id, getReqUserId());
  }

}
