package com.usky.iot.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.iot.domain.BaseGgpFacility;
import com.usky.iot.domain.VcDevice;
import com.usky.iot.domain.VcStream;
import com.usky.iot.service.VcDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

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

/**
 * <p>
 * 视频配置信息表 前端控制器
 * </p>
 *
 * @author han
 * @since 2024-10-22
 */
@RestController
@RequestMapping("/vcDevice")
public class VcDeviceController {

    @Autowired
    private VcDeviceService vcDeviceService;

    /**
     * 视频设备信息查询
     * @param groupId
     * @return
     */
    @GetMapping("/VcDeviceList")
    public ApiResult<List<VcDevice>> VcDeviceList(@RequestParam(value = "groupId",required = false) Integer groupId)
    {
        return ApiResult.success(vcDeviceService.VcDeviceList(groupId));
    }

    /**
     * 视频设备信息分页查询
     *
     * @param videoNumber
     * @param videoName
     * @param groupId
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public ApiResult<CommonPage<VcDevice>> pageList(@RequestParam(value = "videoNumber", required = false, defaultValue = "") String videoNumber,
                                                     @RequestParam(value = "videoName", required = false, defaultValue = "") String videoName,
                                                     @RequestParam(value = "groupId", required = false, defaultValue = "") Integer groupId,
                                                     @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                     @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return ApiResult.success(vcDeviceService.pageList(videoNumber, videoName, groupId, pageNum, pageSize));
    }

    /**
     * 实时拉取摄像头视频流
     * @param deviceUuid
     * @return
     */
    @GetMapping("getVcDeviceVideo")
    public ApiResult<String> getVcDeviceVideo(@RequestParam(value = "deviceUuid") String deviceUuid) {
        return ApiResult.success(vcDeviceService.getVcDeviceVideo(deviceUuid));
    }

    /**
     * 停止拉取摄像头视频流
     */
    @GetMapping("stopDeviceVideo")
    public void stopDeviceVideo(){
        vcDeviceService.stopDeviceVideo();
    }

    /**
     * 新增
     * @param vcDevice
     * @return
     */
    @PostMapping("/add")
    public ApiResult<Void> add(@RequestBody VcDevice vcDevice){
        vcDeviceService.add(vcDevice);
        return ApiResult.success();
    }

    /**
     * 修改
     * @param vcDevice
     * @return
     */
    @PutMapping("/edit")
    public ApiResult<Void> edit(@RequestBody VcDevice vcDevice){
        vcDeviceService.update(vcDevice);
        return ApiResult.success();
    }

    /**
     * 删除记录
     */
    @DeleteMapping("/{id}")
    public ApiResult<Void> remove(@PathVariable("id") Integer id)
    {
        vcDeviceService.remove(id);
        return ApiResult.success();
    }
}

