using BLL;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web.Http;
namespace WebAPI.Controllers
{
    /// 
    /// 
    /// 
    public class VideoController : ApiController
    {
        /// 
        /// 
        /// 
        /// 
        /// 
        public Model.ResponeData getVideoInfor(string projectId)
        {
            Model.ResponeData responeData = new Model.ResponeData();
            try
            {
                string url =ConfigurationManager.AppSettings["Video_URL"];
                List> data = new List>();
                responeData.data = data;
                List urls = new List();
                string res = APIGetHttpService.Http(url + "api/v1/device/channeltree");
                var name = BLL.ProjectService.GetProjectNameByProjectId(projectId);
                List> jsonNvr = JsonConvert.DeserializeObject>>(res);
                foreach (Dictionary nvr in jsonNvr)
                {
                    if (nvr["customName"] == name)
                    {
                        string jsonCameras = APIGetHttpService.Http(url + "api/v1/device/channeltree?serial=" + nvr["serial"]);
                        data.AddRange(JsonConvert.DeserializeObject>>(jsonCameras));
                    }
                }
            }
            catch (Exception ex)
            {
                responeData.code = 0;
                responeData.message = ex.Message;
                ErrLogInfo.WriteLog(ex, "WX接口-监控视频", "VideoController.getVideoInfor");
            }
            return responeData;
        }
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        public Model.ResponeData getVideoUrl(string projectId, string serial, string code)
        {
            var responeData = new Model.ResponeData();
            try
            {
                string url =  ConfigurationManager.AppSettings["Video_URL"];
                var stmp = new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds() + "";
                string jsonCamera = APIGetHttpService.Http(url +"api/v1/stream/start?serial=" + serial + "&code=" + code + "&_=" + stmp);
                responeData.data = JsonConvert.DeserializeObject>(jsonCamera);
            }
            catch (Exception ex)
            {
                responeData.code = 0;
                responeData.message = ex.Message;
                ErrLogInfo.WriteLog(ex, "WX接口-监控视频", "VideoController.getVideoUrl");
            }
            return responeData;
        }
    }
}