package beilv.hik.controller;


import beilv.common.config.RuoYiConfig;
import beilv.common.core.controller.BaseController;
import beilv.common.core.domain.AjaxResult;
import beilv.hik.controller.utils.GetCameraPreviewURL;
import beilv.hik.controller.vo.CompetitionInfo;
import beilv.stadium.domain.Stadium;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
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.ResponseBody;
import org.springframework.web.servlet.ModelAndView;


@Controller
@RequestMapping("/system/hik")
public class HiKController extends BaseController {

//    private String prefix = "system/hik";

//    @GetMapping("/{cameraIndexCode}")
//    public String hik(@PathVariable("cameraIndexCode") String cameraIndexCode) {
//        return prefix + "/hik";
//    }

    @GetMapping()
    public Object hik(CompetitionInfo obj, ModelMap mmap) {
        ModelAndView modelAndView = new ModelAndView("system/hik/hik");
        modelAndView.addObject("dataSource", obj);
        mmap.put("version", RuoYiConfig.getVersion());
        return modelAndView;
    }

    @Value("${hik.appKey}")
    private String appKey;
    @Value("${hik.appSecret}")
    private String appSecret;
    @Value("${hik.host}")
    private String host;

    /**
     * 获取直播流地址
     */
    @GetMapping("/getCameraPreviewURL/{cameraIndexCode}")
    @ResponseBody
    public AjaxResult getCameraPreviewURL(@PathVariable("cameraIndexCode") String cameraIndexCode) {
        String cameraPreviewURL = GetCameraPreviewURL.getCameraPreviewURL(host, appKey, appSecret, cameraIndexCode);
        return AjaxResult.success("操作成功", cameraPreviewURL);
    }
}
