package com.red.circle.other.adapter.app.team;

import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.common.business.dto.cmd.app.AppFlowCmd;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.app.dto.clientobject.team.*;
import com.red.circle.other.app.dto.cmd.team.BdInviteQryCmd;
import com.red.circle.other.app.dto.cmd.team.DbInviteAgentCmd;
import com.red.circle.other.app.dto.cmd.team.DbInviteMessageProcessCmd;
import com.red.circle.other.app.dto.cmd.team.DbLeaderInviteBdCmd;
import com.red.circle.other.app.service.team.TeamBdService;
import com.red.circle.other.infra.database.mongo.entity.team.bd.MessageInviteGroup;
import java.util.List;

import com.red.circle.other.inner.model.cmd.team.bd.BdTeamPageQryCmd;
import com.red.circle.other.inner.model.dto.agency.bd.BdTeamInfoDTO;
import com.red.circle.other.inner.model.dto.agency.bd.BdTeamMemberDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
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>
 * BD团队 前端控制器.
 * </p>
 *
 * @author pengshigang
 * @eo.api-type http
 * @eo.groupName 团队服务.BD团队
 * @eo.path /team/bd
 * @since 2022-06-07
 */
@Slf4j
@RestController
@RequestMapping(value = "/team/bd", produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class TeamBdRestController extends BaseController {

  private final TeamBdService teamBdService;

  /**
   * 获得bd角色.
   *
   * @eo.name 获得bd角色.
   * @eo.url /role
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/role")
  public String getBdRole(AppExtCommand cmd) {
    return teamBdService.getBdRole(cmd);
  }

  /**
   * BD进入系统.
   *
   * @eo.name BD进入系统.
   * @eo.url /entry-sys
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/entry-sys")
  public EntryBdCO bdEntrySys(AppExtCommand cmd) {
    return teamBdService.bdEntrySys(cmd);
  }

  /**
   * BD Leader名下BD列表.
   *
   * @eo.name BD Leader名下BD列表.
   * @eo.url /leader-bd/list
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/leader-bd/list")
  public List<TeamDbMemberCO> listBdMembers(AppFlowCmd cmd) {
    return teamBdService.listBdMembers(cmd);
  }

  /**
   * BD名下代理分页.
   *
   * @eo.name BD名下代理分页.
   * @eo.url /bd-agent/list
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/bd-agent/list")
  public List<TeamDbAgentMemberCO> pageBdTeam(AppFlowCmd cmd) {
    return teamBdService.listBdAgent(cmd);
  }

  /**
   * BD名下代理情况统计.
   *
   * @eo.name BD名下代理情况统计.
   * @eo.url /agent-count
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/agent-count")
  public BdAgentCountCO agentCount(AppExtCommand cmd) {
    return teamBdService.getBdAgentCount(cmd);
  }

    /**
     * BD名下代理情况统计(上个月)
     */
    @GetMapping("/agent-count-last")
    public BdAgentCountCO agentCountLastMonth(AppExtCommand cmd) {
        return teamBdService.getBdAgentLastCount(cmd);
    }

  /**
   * 是否为BD.
   *
   * @eo.name 是否为BD.
   * @eo.url /check
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/check")
  public Boolean checkBD(AppExtCommand cmd) {
    return teamBdService.checkBD(cmd);
  }

  /**
   * 邀请成为BD-邀请BD.
   *
   * @eo.name 邀请成为BD-邀请BD.
   * @eo.url /invite-bd
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/invite-bd")
  public void inviteBd(@RequestBody @Validated DbLeaderInviteBdCmd cmd) {
    teamBdService.inviteBd(cmd);
  }

  /**
   * 获取被Bd邀请消息-邀请BD.
   *
   * @eo.name 获取被Bd邀请消息-邀请BD.
   * @eo.url /invite-bd-message
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/invite-bd-message")
  public List<BdInviteMessageCO> listInviteBdMessage(BdInviteQryCmd cmd) {
    cmd.setGroup(MessageInviteGroup.BD_LEADER_INVITE_BD.name());
    return teamBdService.listBdInviteMessage(cmd);
  }

  /**
   * 处理邀请-邀请BD.
   *
   * @eo.name 处理邀请-邀请BD.
   * @eo.url /invite-bd-message-process
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/invite-bd-message-process")
  public void processInviteBdMessage(@RequestBody @Validated DbInviteMessageProcessCmd cmd) {
    teamBdService.processBdLeaderInviteMessage(cmd);
  }

  /**
   * Bd邀请成为代理-邀请代理.
   *
   * @eo.name Bd邀请成为代理-邀请代理.
   * @eo.url /invite-agent
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/invite-agent")
  public void inviteAgent(@RequestBody @Validated DbInviteAgentCmd cmd) {
    teamBdService.inviteAgent(cmd);
  }

  /**
   * 获取被Bd邀请消息-邀请代理.
   *
   * @eo.name 获取被Bd邀请消息-邀请代理.
   * @eo.url /invite-message
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/invite-message")
  public List<BdInviteMessageCO> listBdInviteMessage(BdInviteQryCmd cmd) {
    cmd.setGroup(MessageInviteGroup.BD_INVITE_TEAM.name());
    return teamBdService.listBdInviteMessage(cmd);
  }

  /**
   * 处理邀请-邀请代理.
   *
   * @eo.name 处理邀请-邀请代理.
   * @eo.url /invite-message-process
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/invite-message-process")
  public void processBdInviteMessage(@RequestBody @Validated DbInviteMessageProcessCmd cmd) {
    teamBdService.processBdInviteMessage(cmd);
  }

    /**
     * BD 列表接口
     */
  @GetMapping("/page2")
  public PageResult<BdPageCO> bdPage(BdTeamPageQryCmd qryCmd) {
      return teamBdService.bdPage(qryCmd);
  }

}
