package com.zcloud.zcGbsServicer.web;

import com.alibaba.cola.dto.SingleResponse;
import com.zcloud.zcGbsServicer.api.VideoPlatformServiceI;
import com.zcloud.zcGbsServicer.dto.VideoPlatformDepartmentQry;
import com.zcloud.zcGbsServicer.dto.VideoPlatformFixedRoomLeaveCmd;
import com.zcloud.zcGbsServicer.dto.VideoPlatformFixedRoomLoginCmd;
import com.zcloud.zcGbsServicer.dto.VideoPlatformFixedRoomQry;
import com.zcloud.zcGbsServicer.dto.VideoPlatformMeetingAccessCheckQry;
import com.zcloud.zcGbsServicer.dto.VideoPlatformMeetingMemberQry;
import com.zcloud.zcGbsServicer.dto.VideoPlatformUserQry;
import com.zcloud.zcGbsServicer.dto.VideoRoomAuthRoomCmd;
import com.zcloud.zcGbsServicer.dto.VideoRoomAuthUserCmd;
import com.zcloud.zcGbsServicer.dto.VideoRoomCreateInstantCmd;
import com.zcloud.zcGbsServicer.dto.VideoRoomOnlineRoomQry;
import com.zcloud.zcGbsServicer.dto.clientobject.VideoPlatformConfigCO;
import com.zcloud.zcGbsServicer.dto.clientobject.VideoPlatformCurrentMeetingCO;
import com.zcloud.zcGbsServicer.dto.clientobject.VideoPlatformLoginCO;
import com.zcloud.zcGbsServicer.dto.clientobject.VideoPlatformMeetingAccessCheckCO;
import com.zcloud.zcGbsServicer.dto.clientobject.VideoPlatformMeetingMemberStatusCO;
import com.zcloud.zcGbsServicer.dto.clientobject.VideoPlatformOnlineRoomPageCO;
import com.zcloud.zcGbsServicer.dto.clientobject.VideoPlatformResultCO;
import com.zcloud.zcGbsServicer.dto.clientobject.VideoPlatformTokenCO;
import com.zcloud.zcGbsServicer.dto.clientobject.VideoRoomInstantCO;
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.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

@Api(tags = "消防报警视频会议")
@RestController
@AllArgsConstructor
public class VideoPlatformController {

    private final VideoPlatformServiceI videoPlatformService;

    @ApiOperation("获取视频平台基础配置")
    @GetMapping({"/${application.gateway}/video/platform/config", "/video/platform/config"})
    public SingleResponse<VideoPlatformConfigCO> getConfig() {
        return videoPlatformService.getConfig();
    }

    @ApiOperation("生成视频平台调试令牌")
    @PostMapping({"/${application.gateway}/api/v1/video/token/generate", "/api/v1/video/token/generate"})
    public SingleResponse<VideoPlatformTokenCO> generateToken() {
        return videoPlatformService.generateToken();
    }

    @ApiOperation("创建即时会议")
    @PostMapping({"/${application.gateway}/api/v1/room/createInstant", "/api/v1/room/createInstant"})
    public SingleResponse<VideoRoomInstantCO> createInstant(@Validated @RequestBody(required = false) VideoRoomCreateInstantCmd cmd) {
        return videoPlatformService.createInstant(cmd == null ? new VideoRoomCreateInstantCmd() : cmd);
    }

    @ApiOperation("会议室授权用户")
    @PostMapping({"/${application.gateway}/api/v1/room/authUser", "/api/v1/room/authUser"})
    public SingleResponse<VideoPlatformResultCO> authUser(@Validated @RequestBody VideoRoomAuthUserCmd cmd) {
        return videoPlatformService.authUser(cmd);
    }

    @ApiOperation("用户授权会议室")
    @PostMapping({"/${application.gateway}/api/v1/room/authRoom", "/api/v1/room/authRoom"})
    public SingleResponse<VideoPlatformResultCO> authRoom(@Validated @RequestBody VideoRoomAuthRoomCmd cmd) {
        return videoPlatformService.authRoom(cmd);
    }

    @ApiOperation("获取视频平台登录地址")
    @GetMapping({"/${application.gateway}/api/v1/room/loginAddr", "/api/v1/room/loginAddr"})
    public SingleResponse<List<String>> getLoginAddr() {
        List<String> loginAddrList = videoPlatformService.getLoginAddr();
        return SingleResponse.of(loginAddrList == null ? Collections.emptyList() : loginAddrList);
    }

    @ApiOperation("查询在线视频会议")
    @PostMapping({"/${application.gateway}/api/v1/room/onlineRoom", "/api/v1/room/onlineRoom"})
    public SingleResponse<VideoPlatformOnlineRoomPageCO> onlineRoom(@RequestBody(required = false) VideoRoomOnlineRoomQry qry) {
        return videoPlatformService.onlineRoom(qry == null ? new VideoRoomOnlineRoomQry() : qry);
    }

    @ApiOperation("查询视频平台组织架构")
    @PostMapping({"/${application.gateway}/video/platform/department/list", "/video/platform/department/list"})
    public SingleResponse<VideoPlatformResultCO> departmentList(@RequestBody(required = false) VideoPlatformDepartmentQry qry) {
        return videoPlatformService.departmentList(qry == null ? new VideoPlatformDepartmentQry() : qry);
    }

    @ApiOperation("查询视频平台用户")
    @PostMapping({"/${application.gateway}/video/platform/user/list", "/video/platform/user/list"})
    public SingleResponse<VideoPlatformResultCO> userList(@RequestBody(required = false) VideoPlatformUserQry qry) {
        return videoPlatformService.userList(qry == null ? new VideoPlatformUserQry() : qry);
    }

    @ApiOperation("查看当前固定消防会议")
    @PostMapping({"/${application.gateway}/video/platform/fixedRoom/current", "/video/platform/fixedRoom/current"})
    public SingleResponse<VideoPlatformCurrentMeetingCO> currentFixedMeeting(@RequestBody(required = false) VideoPlatformFixedRoomQry qry) {
        return videoPlatformService.currentFixedMeeting(qry == null ? new VideoPlatformFixedRoomQry() : qry);
    }

    @ApiOperation("固定消防会议入会校验")
    @PostMapping({"/${application.gateway}/video/platform/fixedRoom/access/check", "/video/platform/fixedRoom/access/check"})
    public SingleResponse<VideoPlatformMeetingAccessCheckCO> checkFixedMeetingAccess(@RequestBody(required = false) VideoPlatformMeetingAccessCheckQry qry) {
        return videoPlatformService.checkFixedMeetingAccess(qry == null ? new VideoPlatformMeetingAccessCheckQry() : qry);
    }

    @ApiOperation("固定消防会议参会成员状态")
    @PostMapping({"/${application.gateway}/video/platform/fixedRoom/members", "/video/platform/fixedRoom/members"})
    public SingleResponse<VideoPlatformMeetingMemberStatusCO> fixedMeetingMembers(@RequestBody(required = false) VideoPlatformMeetingMemberQry qry) {
        return videoPlatformService.fixedMeetingMembers(qry == null ? new VideoPlatformMeetingMemberQry() : qry);
    }

    @ApiOperation("获取固定会议室入会参数")
    @PostMapping({"/${application.gateway}/video/platform/fixedRoom/login", "/video/platform/fixedRoom/login"})
    public SingleResponse<VideoPlatformLoginCO> fixedRoomLogin(@RequestBody(required = false) VideoPlatformFixedRoomLoginCmd cmd) {
        return videoPlatformService.fixedRoomLogin(cmd == null ? new VideoPlatformFixedRoomLoginCmd() : cmd);
    }

    @ApiOperation("固定会议室离会回调")
    @PostMapping({"/${application.gateway}/video/platform/fixedRoom/leave", "/video/platform/fixedRoom/leave"})
    public SingleResponse<VideoPlatformResultCO> fixedRoomLeave(@RequestBody(required = false) VideoPlatformFixedRoomLeaveCmd cmd) {
        return videoPlatformService.fixedRoomLeave(cmd == null ? new VideoPlatformFixedRoomLeaveCmd() : cmd);
    }
}
