package com.zd.iot.vmp.web;

import com.zd.iot.vmp.common.StreamInfo;
import com.zd.iot.vmp.service.IMediaService;
import com.zd.iot.vmp.vmanager.bean.WVPResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@CrossOrigin
@RestController
public class ApiCompatibleController {

    private final static Logger logger = LoggerFactory.getLogger(ApiCompatibleController.class);

    @Autowired
    private IMediaService mediaService;

    @GetMapping(value = "/api/v1/stream_info_by_app_and_stream")
    @ResponseBody
    public WVPResult<StreamInfo> getStreamInfoByAppAndStream(HttpServletRequest request, @RequestParam String app, @RequestParam String stream){
        String localAddr = request.getLocalAddr();
        localAddr="your_server_id";
        StreamInfo streamINfo = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, localAddr);
        WVPResult<StreamInfo> wvpResult = new WVPResult<>();
        wvpResult.setCode(0);
        wvpResult.setMsg("success");
        wvpResult.setData(streamINfo);
        return wvpResult;
    }
}
