package com.ruoyi.cai.controller.app;

import com.ruoyi.cai.chat.ChatManager;
import com.ruoyi.cai.dto.app.query.CallReq;
import com.ruoyi.cai.dto.app.vo.chat.CallResp;
import com.ruoyi.cai.dto.app.vo.chat.GetRoomResp;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;

@RestController
@RequestMapping("/api/room")
@Tag(name = "直播相关接口")
@Validated
public class RoomController {

    @Autowired
    private ChatManager chatManager;

    @PostMapping("/call")
    @Operation(summary = "发起直播")
    @Log(title = "发起直播", businessType = BusinessType.OTHER, isSaveDb = false)
    public R<CallResp> call(@RequestBody CallReq req){
        CallResp call = chatManager.call(req);
        return R.ok(call);
    }

    @GetMapping("/getRoom")
    @Operation(summary = "获取房间信息")
    @Log(title = "获取房间信息", businessType = BusinessType.OTHER, isSaveDb = false)
    public R<GetRoomResp> getRoom(@NotEmpty(message = "房间不存在") String roomId){
        GetRoomResp room = chatManager.getRoom(roomId);
        return R.ok(room);
    }
}
