package com.ningdatech.carapi.car.video.controller;

import java.util.List;

import javax.validation.Valid;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.alibaba.fastjson.JSONObject;
import com.ningdatech.carapi.car.position.model.vo.DeviceVO;
import com.ningdatech.carapi.car.video.manage.VideoMonitorManage;
import com.ningdatech.carapi.car.video.model.dto.PlaybackVideoParamDTO;
import com.ningdatech.carapi.car.video.model.dto.PlaybackVideoStartParamDTO;
import com.ningdatech.carapi.car.video.model.vo.PlaybackVideoVO;
import com.ningdatech.log.annotation.WebLog;

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

/**
 * @author Poffy Zhang
 * @date 2022/11/01 上午10:25
 */

@RestController
@RequestMapping(value = "/api/v1/car-manage/video-monitor")
@Api(tags = "车辆管理-视频监控")
@Validated
@RequiredArgsConstructor
public class VideoMonitorController {

    private final VideoMonitorManage videoMonitorManage;

    @ApiOperation("获取某辆车在线的设备")
    @GetMapping("/get-online-devices/{carPlate}")
    public List<DeviceVO> getOnlineDevices(@Valid @PathVariable String carPlate) {
        return videoMonitorManage.getOnlineDevices(carPlate);
    }

    @ApiOperation("开始预览设备")
    @PostMapping("/start-play/{deviceId}")
    @WebLog
    public JSONObject startPlay(@Valid @PathVariable String deviceId) {
        return videoMonitorManage.startPlay(deviceId);
    }

    @ApiOperation("结束预览设备")
    @PostMapping("/stop-play/{deviceId}")
    @WebLog
    public void stopPlay(@Valid @PathVariable String deviceId) {
        videoMonitorManage.stopPlay(deviceId);
    }

    @ApiOperation("获取回放视频列表")
    @GetMapping("/playback-videos")
    @WebLog
    public List<PlaybackVideoVO> playBackVideos(@Valid @ModelAttribute PlaybackVideoParamDTO param) {
        return videoMonitorManage.playBackVideos(param);
    }

    @ApiOperation("开始播放回放流视频")
    @PostMapping("/start-playback")
    @WebLog
    public JSONObject startPlayBack(@Valid @RequestBody PlaybackVideoStartParamDTO param) {
        return videoMonitorManage.startPlayBack(param);
    }

    @ApiOperation("结束播放回放流视频")
    @PostMapping("/stop-playback/{streamId}")
    @WebLog
    public JSONObject stopPlayBack(@Valid @PathVariable String streamId) {
        return videoMonitorManage.stopPlayBack(streamId);
    }
}
