package com.ningdatech.pmapi.meeting.controller;


import com.ningdatech.basic.model.IdVo;
import com.ningdatech.basic.model.PageVo;
import com.ningdatech.log.annotation.WebLog;
import com.ningdatech.pmapi.meeting.entity.req.*;
import com.ningdatech.pmapi.meeting.entity.vo.*;
import com.ningdatech.pmapi.meeting.manage.MeetingManage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 会议 前端控制器
 * </p>
 *
 * @author WendyYang
 * @since 2022-07-26
 */
@Validated
@RestController
@AllArgsConstructor
@Api(tags = "会议管理")
@RequestMapping("/api/v1/meeting")
public class MeetingController {

    private final MeetingManage meetingManage;

    @PostMapping("/create")
    @ApiOperation(value = "新建会议")
    @WebLog(value = "新建会议")
    public IdVo<Long> meetingCreate(@Valid @RequestBody MeetingCreateReq req) {
        return meetingManage.meetingCreateAndInviteExpert(req);
    }

    @PostMapping("/continueInvite")
    @ApiOperation(value = "续抽专家")
    @WebLog(value = "续抽专家")
    public void continueInvite(@Valid @RequestBody MeetingIdReq req) {
        meetingManage.continueInvite(req.getMeetingId());
    }

    @PostMapping("/convertToAppoint")
    @ApiOperation(value = "转为指定抽取")
    @WebLog(value = "转为指定抽取")
    public void convertToAppoint(@Valid @RequestBody MeetingIdReq req) {
        meetingManage.convertToAppoint(req.getMeetingId());
    }

    @PostMapping("/expertInviteByCreate")
    @ApiOperation(value = "新建会议-专家抽取", hidden = true)
    @WebLog(value = "新建会议-专家抽取")
    public void expertInviteByCreate(@Valid @RequestBody ExpertInviteReq po) {
        meetingManage.expertInviteByCreate(po);
    }

    @ApiOperation("专家抽取数量校验")
    @PostMapping("/expertCountOnChange")
    public ExpertCountOnChangeVO expertCountOnChange(@RequestBody ExpertInviteReq po) {
        return meetingManage.expertCountOnChange(po);
    }

    @ApiOperation("管理员会议列表")
    @GetMapping("/manager/meetingList")
    @WebLog(value = "管理员会议列表")
    public PageVo<MeetingByManagerVO> meetingListByManager(MeetingListReq req) {
        return meetingManage.meetingListByManager(req);
    }

    @ApiOperation("专家会议列表")
    @GetMapping("/expert/meetingList")
    @WebLog(value = "专家会议列表")
    public PageVo<MeetingByManagerVO> meetingListByExpert(MeetingListReq po) {
        return meetingManage.meetingListByExpert(po);
    }

    @ApiOperation("会议详情-基本信息")
    @GetMapping("/basicInfo/{meetingId}")
    @WebLog(value = "会议详情-基本信息")
    public MeetingDetailBasicVO meetingBasic(@PathVariable Long meetingId) {
        return meetingManage.getMeetingDetail(meetingId);
    }

    @ApiOperation("抽取情况")
    @GetMapping("/inviteExpertList/{meetingId}")
    @WebLog(value = "邀请情况详请")
    public ExpertInviteDetailVO inviteExpertList(@PathVariable Long meetingId) {
        return meetingManage.inviteExpertList(meetingId);
    }

    @ApiOperation("会议基础信息修改")
    @PostMapping("/basicInfo/modify")
    @WebLog(value = "会议基础信息修改")
    public void meetingBasicInfoModify(@Valid @RequestBody MeetingBasicInfoModifyReq po) {
        meetingManage.meetingBasicInfoModify(po);
    }

    @ApiOperation("会议详情-抽取规则")
    @GetMapping("/inviteRuleDetail/{meetingId}")
    @WebLog(value = "会议详情-抽取规则")
    public InviteRuleDetailVO inviteRuleDetail(@PathVariable Long meetingId) {
        return meetingManage.inviteRuleDetail(meetingId);
    }

    @ApiOperation("停止抽取")
    @GetMapping("/stopInvite/{meetingId}")
    @WebLog(value = "停止抽取")
    public void stopInvite(@PathVariable Long meetingId) {
        meetingManage.stopRandomInvite(meetingId);
    }

    @ApiOperation("取消会议")
    @PostMapping("/cancel")
    @WebLog(value = "取消会议")
    public void cancelMeeting(@Valid @RequestBody MeetingCancelReq po) {
        meetingManage.cancelMeeting(po);
    }

    @ApiOperation("邀请函信息")
    @GetMapping("/expertInviteDetail")
    @WebLog(value = "邀请函信息")
    public ExpertInvitationDetailVO expertInvitationDetail(@RequestParam(required = false) Long expertId,
                                                           @RequestParam Long meetingId) {
        return meetingManage.expertInvitationDetail(meetingId, expertId);
    }

    @ApiOperation("补充专家（指定抽取）")
    @PostMapping("/expert/batchAppoint")
    @WebLog(value = "批量补充专家")
    public void batchAppointExperts(@Valid @RequestBody BatchAppointExpertsReq po) {
        meetingManage.batchAppointExperts(po);
    }

    @ApiOperation("确认参加")
    @PostMapping("/expert/confirm")
    @WebLog(value = "确认参加")
    public void confirmAttendByManager(@RequestBody ExpertConfirmReq req) {
        meetingManage.confirmAttendByManager(req);
    }

    @ApiOperation("释放专家")
    @PostMapping("/expert/release")
    @WebLog(value = "释放专家")
    public void releaseExperts(@RequestBody MeetingCancelReq req) {
        meetingManage.releaseExperts(req);
    }

    @ApiOperation("设置专家组长")
    @PostMapping("setUpHeadman")
    @WebLog(value = "设置专家组长")
    public void setUpHeadman(@RequestBody ExpertConfirmReq req) {
        meetingManage.setUpHeadman(req);
    }

    @ApiOperation("重发短信")
    @PostMapping("/confirmedRoster")
    @WebLog(value = "重发短信")
    public void resendSms(MeetingCancelReq req) {
        meetingManage.confirmedRoster(req.getMeetingId());
    }

}
