package com.yonge.cooleshow.student.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.biz.dal.entity.ImUserStateSync;
import com.yonge.cooleshow.biz.dal.entity.RoomInfoCache;
import com.yonge.cooleshow.biz.dal.service.LiveRoomService;
import com.yonge.cooleshow.biz.dal.service.StudentService;
import com.yonge.cooleshow.biz.dal.vo.TeacherLivingInfoVo;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;

/**
 * 直播房间与课程的关系表表(LiveRoom)表控制层
 *
 * @author hgw
 * @since 2022-03-18 15:41:16
 */
@Api(tags = "直播房间与课程的关系表表")
@RestController
@RequestMapping("/liveRoom")
public class StudentLiveRoomController extends BaseController {
    private final static Logger log = LoggerFactory.getLogger(StudentLiveRoomController.class);
    /**
     * 服务对象
     */
    @Resource
    private LiveRoomService liveRoomService;
    
    @Autowired
    private SysUserFeignService sysUserFeignService;
    
    @Autowired
    private StudentService studentService;

    /**
     * 校验房间信息，及个人信息
     *
     * @param roomUid 房间uid
     */
    @GetMapping("/studentCheckRoomInfo")
    public HttpResponseResult<RoomInfoCache> studentCheckRoomInfo(@RequestParam("roomUid") String roomUid) {
        return succeed(liveRoomService.studentCheckRoomInfo(roomUid));
    }

    @ApiOperation("观看者-进入房间")
    @GetMapping(value = "/joinRoom")
    public HttpResponseResult<RoomInfoCache> joinRoom(String roomUid, Long userId) {
        return succeed(liveRoomService.joinRoom(roomUid, userId));
    }

    /**
     * 同步融云用户状态变更
     *
     * @param userState
     */
    @PostMapping(value = "/syncUserStatus")
    public void statusImUser(@RequestBody List<ImUserStateSync> userState) {
        log.info("opsRoom >>>>> : {}", JSONObject.toJSONString(userState));
        liveRoomService.opsRoom(userState);
    }

    @ApiOperation("方便测试观察房间数据的方法")
    @GetMapping("/test")
    public Object destroyExpiredLiveRoom(@RequestParam("roomUid") String roomUid) {
        return liveRoomService.test(roomUid);
    }

    @ApiOperation("老师直播列表")
    @GetMapping("/queryTeacherLivingList")
    public HttpResponseResult<List<TeacherLivingInfoVo>> queryTeacherLivingList() {

        return succeed(liveRoomService.queryTeacherLivingList());
    }

}

