package com.fs.live.controller;

import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.LiveBroadcastEnum;
import com.fs.live.dto.LiveBroadcastDto;
import com.fs.live.domain.LiveBroadcast;
import com.fs.live.service.ILiveBroadcastService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 直播列表Controller
 * 
 * @author fs
 * @date 2026-03-10
 */
@RestController
public class LiveRemoteController extends BaseController
{
    @Autowired
    private ILiveBroadcastService liveBroadcastService;

    @ApiOperation("开始直播")
    @PostMapping("/startLive")
    public AjaxResult startLive(@RequestBody LiveBroadcastDto liveBroadcastDto)
    {
        LiveBroadcast liveBroadcast = new LiveBroadcast();
        liveBroadcast.setActualStartTime(new Date());
        liveBroadcast.setId(liveBroadcastDto.getSysLiveId());
        liveBroadcast.setStatus(LiveBroadcastEnum.STARTING.getCode());
        liveBroadcastService.updateLiveBroadcast(liveBroadcast);

        System.out.println("调用了开始直播接口");
        return AjaxResult.success("开始直播");
    }

    @ApiOperation("结束直播")
    @PostMapping("/closeLive")
    public AjaxResult closeLive(@RequestBody LiveBroadcastDto liveBroadcastDto)
    {
        liveBroadcastService.closeLive(liveBroadcastDto);
        System.out.println("调用了结束直播接口");
        return AjaxResult.success("结束直播");
    }

    @ApiOperation("liveKit用户动态回调接口")
    @PostMapping("/userStatusCallback")
    public AjaxResult userStatusCallback(@RequestBody LiveBroadcastDto liveBroadcastDto)
    {
        System.out.println("-----------------用户动态回调执行了---------------------");
        return AjaxResult.success("结束直播");
    }
}
