package cn.iocoder.yudao.module.pms.controller.admin.yanfan.media;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.pms.service.yanfan.play.IPlayService;
import cn.iocoder.yudao.module.pms.service.yanfan.play.model.Stream;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Slf4j
@RestController
@RequestMapping("/rq/sip/player")
public class PlayerController {
    @Autowired
    private IPlayService playService;

    @GetMapping("/getBigScreenUrl/{deviceId}/{channelId}")
    public CommonResult<String> getBigScreenUrl(@PathVariable String deviceId, @PathVariable String channelId) {
//        return AjaxResult.success(MessageUtils.message("success"), playService
//                .play(deviceId, channelId, false)
//                .getHttps_fmp4());
        return success(playService
                .play(deviceId, channelId, false)
                .getHttps_fmp4());
    }

    @Operation(summary="直播播放")
    @GetMapping("/play/{deviceId}/{channelId}")
    public CommonResult<Stream> play(@PathVariable String deviceId, @PathVariable String channelId) {
        return success(playService.play(deviceId, channelId, false));
    }

    @Operation(summary="回放播放")
    @GetMapping("/playback/{deviceId}/{channelId}")
    public CommonResult<Stream> playback(@PathVariable String deviceId, @PathVariable String channelId, String start, String end) {
        return success(playService.playback(deviceId, channelId, start, end));
    }

    @Operation(summary="停止推流")
    @GetMapping("/closeStream/{deviceId}/{channelId}/{streamId}")
    public CommonResult<String> closeStream(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String streamId) {
        return success(playService.closeStream(deviceId, channelId, streamId));
    }

    @Operation(summary="回放暂停")
    @GetMapping("/playbackPause/{deviceId}/{channelId}/{streamId}")
    public CommonResult<String> playbackPause(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String streamId) {
        return success(playService.playbackPause(deviceId, channelId, streamId));
    }

    @Operation(summary="回放恢复")
    @GetMapping("/playbackReplay/{deviceId}/{channelId}/{streamId}")
    public CommonResult<String> playbackReplay(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String streamId) {
        return success(playService.playbackReplay(deviceId, channelId, streamId));
    }

    @Operation(summary="录像回放定位")
    @GetMapping("/playbackSeek/{deviceId}/{channelId}/{streamId}")
    public CommonResult<String> playbackSeek(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String streamId, long seek) {
        return success(playService.playbackSeek(deviceId, channelId, streamId, seek));
    }

    @Operation(summary="录像倍速播放")
    @GetMapping("/playbackSpeed/{deviceId}/{channelId}/{streamId}")
    public CommonResult<String> playbackSpeed(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String streamId, Integer speed) {
        return success(playService.playbackSpeed(deviceId, channelId, streamId, speed));
    }
}
