package com.yonge.cooleshow.teacher.controller;


import com.alibaba.fastjson.JSONObject;
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.vo.RoomVo;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

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

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

    /**
     * 根据房间uid查询房间信息
     *
     * @param roomUid 房间uid
     */
    @GetMapping("queryRoomInfo")
    public HttpResponseResult<RoomVo> queryRoomInfo(@RequestParam("roomUid") String roomUid) {
        return succeed(liveRoomService.queryRoomInfo(roomUid));
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "roomTitle", dataType = "String", value = "房间标题"),
            @ApiImplicitParam(name = "liveRemark", dataType = "String", value = "直播内容/最多200个字"),
    })
    @ApiOperation("创建临时房间-直播间")
    @PostMapping("/createTempLiveRoom")
    public HttpResponseResult<String> createTempLiveRoom(@RequestBody Map<String, Object> param) {
        return succeed(liveRoomService.createTempLiveRoom(param));
    }

    @ApiOperation("同步点赞数量")
    @GetMapping("/syncLike")
    public HttpResponseResult<Object> syncLike(@ApiParam(value = "房间uid", required = true) String roomUid,
                                       @ApiParam(value = "点赞数", required = true) Integer likeNum) {
        liveRoomService.syncLike(roomUid, likeNum);
        return succeed();
    }

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

    @ApiOperation("定时任务-创建房间-直播间")
    @GetMapping("/createCourseLiveRoom")
    public void createCourseLiveRoom() {
        liveRoomService.createCourseLiveRoom();
    }

    @ApiOperation("定时任务-销毁房间-直播间")
    @GetMapping("/destroyExpiredLiveRoom")
    public void destroyExpiredLiveRoom() {
        liveRoomService.destroyExpiredLiveRoom();
    }

    /**
     * 同步融云用户状态变更
     *
     * @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);
    }

}

