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

import com.red.circle.console.app.dto.clienobject.team.bd.TeamBdCO;
import com.red.circle.console.app.dto.clienobject.team.bd.TeamBdWorkStatisticsCO;
import com.red.circle.console.app.dto.cmd.app.team.bd.TeamBdAddCmd;
import com.red.circle.console.app.service.app.team.bd.TeamBDInfoService;
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.bd.BdTeamPageQryCmd;
import com.red.circle.other.inner.model.cmd.team.bd.BdTeamUpdateOpsCmd;
import com.red.circle.other.inner.model.cmd.team.bd.BdTeamWorkStatisticsQryCmd;
import com.red.circle.other.inner.model.cmd.team.bd.ChangeBdLeaderCmd;
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;

/**
 * <p>
 * 商务拓展基本信息表 前端控制器.
 * </p>
 *
 * @author pengliang on 2023/11/21
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/team/bd")
public class TeamBdInfoRestController extends BaseController {

  private final TeamBDInfoService teamBDInfoService;

  /**
   * BD分页列表.
   */
  @GetMapping("/page")
  public PageResult<TeamBdCO> pageOps(BdTeamPageQryCmd qryCmd) {
    return teamBDInfoService.pageOps(qryCmd);
  }

  /**
   * BD工作统计
   */
  @GetMapping("/work/statistics")
  public PageResult<TeamBdWorkStatisticsCO> pageWorkStatistics(BdTeamWorkStatisticsQryCmd qryCmd) {
    return teamBDInfoService.pageWorkStatistics(qryCmd);
  }

  /**
   * 添加BD.
   */
  @OpsOperationReqLog("添加BD")
  @PostMapping("/add")
  public void add(@RequestBody @Validated TeamBdAddCmd cmd) {
    cmd.setCreateUser(getReqUserId());
    teamBDInfoService.addBd(cmd);
  }

  /**
   * 编辑BD.
   */
  @OpsOperationReqLog("编辑BD")
  @PostMapping("/update")
  public void updateAgent(@RequestBody @Validated BdTeamUpdateOpsCmd cmd) {
    cmd.setUpdateUser(getReqUserId());
    teamBDInfoService.updateById(cmd);
  }

  /**
   * 删除BD.
   */
  @OpsOperationReqLog("删除BD")
  @GetMapping("/del")
  public void deleteById(Long id) {
    teamBDInfoService.deleteById(id, getReqUserId());
  }

  /**
   * 换绑BD Leader.
   */
  @OpsOperationReqLog("换绑BD Leader")
  @PostMapping("/change-bd-leader")
  public void changeBdLeader(@RequestBody @Validated ChangeBdLeaderCmd cmd) {
    cmd.setUpdateUser(getReqUserId());
    teamBDInfoService.changeBdLeader(cmd);
  }


}
