import {get, post} from "@/util/request/index.js";
import {Page} from "@/common/consts/CommonConst";

export const getDeviceList = async ({page = Page.page, size = Page.size, ...params}) => {
  return await post('/device/getDeviceList', {
    page,
    size,
    ...params
  });
}


export const getDeviceDetail = async (id) => {
  return await get(`/device/getDeviceDetail/${id}`)
}

export const getDeviceMeta = async (id) => {
  return await get(`/device/getMetadataInfo/${id}`);
}
export const forbidDevice = async (ids = []) => {
  return await post('/device/forbidDevice', ids);
}
export const startDevice = async (ids = []) => {
  return await post('/device/startDevice', ids);
}

export const scrapDevice = async (data) => {
  return await post('/device/insertScrapDevice', data);
}

export const getDeviceService = async (data) => {
  return await get('/metadataService/getList', data);
}

export const deviceServiceApply = (deviceId, identifer, params) => {
  return post(`/online/device/service/request/${deviceId}/${identifer}`,
    params);
}

export const getAlarmLog = ({page = Page.page, size = Page.size, ...params}) => {
  return post(`/alarm/getAlarmLog`, {
    page,
    size,
    ...params
  });
}

export const getAlarmLogDetail = ({page = Page.page, size = Page.size, ...params}) => {
  return post(`/alarm/findAlarmLogById`, {
    page,
    size,
    ...params
  });
}

export const stopCommand = ({deviceNo, tunnel}) => {
  post(`/wvp/api/ptz/control/${deviceNo}/${tunnel}?command=stop&horizonSpeed=100&verticalSpeed=100&zoomSpeed=100`, {})
}
export const videoCommand = ({deviceNo, tunnel, command}) => {
  post(`/wvp/api/ptz/control/${deviceNo}/${tunnel}?command=${command}&horizonSpeed=100&verticalSpeed=100&zoomSpeed=100`, {}).then(() => {
    setTimeout(() => {
      stopCommand({
        deviceNo,
        tunnel
      })
    }, 1000)
  }).catch(() => {
    stopCommand({
      deviceNo,
      tunnel
    })
  })
}

export const getCameraList = ({page = Page.page, size = Page.size, ...params}) => {
  return get(`/api/wvp/api/device/query/devices`, {
    page,
    size,
    ...params
  });
}
export const getTunnelList = ({page = Page.page, size = Page.size, deviceNo, online = true, ...params}) => {
  return get(`wvp/api/device/query/devices/${deviceNo}/channels`, {
    page,
    count: size,
    online,
    ...params
  });
}

export const getCameraStream = ({deviceNo, tunnel}) => {
  return get(`/wvp/api/play/start/${deviceNo}/${tunnel}`);
}

