package beilv.hik.controller;


import beilv.common.core.controller.BaseController;
import beilv.common.core.domain.AjaxResult;
import beilv.hik.controller.utils.GetCameraPreviewURL;
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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


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

    private String prefix = "system/hik";

    @GetMapping("/{cameraIndexCode}")
    public String hik(@PathVariable("cameraIndexCode") String cameraIndexCode, ModelMap mmap) throws IOException {
        mmap.put("cameraIndexCode", cameraIndexCode);
        return prefix + "/hik";
    }

    @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);
    }
}
