package com.ym.mec.student.controller;

import com.ym.mec.biz.dal.vo.ImLiveBroadcastRoomVo;
import com.ym.mec.biz.service.ImLiveBroadcastRoomService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import com.ym.mec.common.entity.ImUserState;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 直播房间管理表(ImLiveBroadcastRoom)表控制层
 *
 * @author hgw
 * @since 2022-02-17 20:52:04
 */
@Api(tags = "直播房间管理表")
@RestController
@RequestMapping("/imLiveBroadcastRoom")
public class ImLiveBroadcastRoomController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ImLiveBroadcastRoomService imLiveBroadcastRoomService;

    @ApiOperation("学生端-查询房间信息")
    @GetMapping("/queryRoomInfo")
    public HttpResponseResult<ImLiveBroadcastRoomVo> queryRoomInfo(@ApiParam(value = "房间uid", required = true) String roomUid) {
        return succeed(imLiveBroadcastRoomService.queryRoomInfo(roomUid));
    }

    @ApiOperation("查询该机构目前推广的直播间")
    @GetMapping(value = "/queryPopularizeRoom")
    public HttpResponseResult<ImLiveBroadcastRoomVo> queryPopularizeRoom() {
        return succeed(imLiveBroadcastRoomService.queryPopularizeRoom());
    }

    @ApiOperation("查询房间信息并校验房间是否合规")
    @GetMapping("/queryRoom")
    public HttpResponseResult<ImLiveBroadcastRoomVo> queryRoomAndCheck(@ApiParam(value = "房间uid", required = true) String roomUid,
                                                                       @ApiParam(value = "用户id", required = true) Integer userId) {
        return succeed(imLiveBroadcastRoomService.queryRoomAndCheck(roomUid, userId, 1));
    }

    @PostMapping("/quitRoom")
    public HttpResponseResult<Object> quitRoom(@RequestBody List<ImUserState> userState) {
        imLiveBroadcastRoomService.opsRoom(userState);
        return succeed();
    }

    @ApiOperation("学生-进入房间")
    @GetMapping("/joinRoom")
    public HttpResponseResult<Object> joinRoom(String roomUid, Integer userId) {
        imLiveBroadcastRoomService.joinRoom(roomUid, userId);
        return succeed();
    }

}

