import request from '@/service/request'

export const getStreams = () => {
  return request<RTS.STREAM.List[]>({
    url: '/api/streams',
    method: 'GET'
  })
}

export const getStreamsDetail = (streamPath: string) => {
  return request<RTS.STREAM.Detail[]>({
    url: `/api/stream?streamPath=${streamPath}`,
    method: 'GET'
  })
}

export const getSnap = (streamPath: string) => {
  return request<RTS.STREAM.Detail[]>({
    url: `/snap/${streamPath}`,
    method: 'GET'
  })
}

export const closeStream = (streamPath: string) => {
  return request<RTS.STREAM.Detail[]>({
    url: `/api/closestream?streamPath=${streamPath}`,
    method: 'GET'
  })
}

export const getPullList = () => {
  return request<RTS.PullStream.Detail[]>({
    url: '/api/list/pull',
    method: 'GET'
  })
}

export const stopPull = (url: string) => {
  return request<RTS.STREAM.Detail[]>({
    url: `/api/stoppull?url=${url}`,
    method: 'GET'
  })
}

export const createRtspPull = (params: {streamPath: string, target: string, save: number}) => {
  return request<RTS.STREAM.Detail[]>({
    url: '/rtsp/api/pull',
    method: 'GET',
    params
  })
}

export const createRtmpPull = (params: {streamPath: string, target: string, save: number}) => {
  return request<RTS.STREAM.Detail[]>({
    url: '/rtmp/api/pull',
    method: 'GET',
    params
  })
}

export const getPushList = () => {
  return request<RTS.PullStream.Detail[]>({
    url: '/api/list/push',
    method: 'GET'
  })
}

export const stopPush = (url: string) => {
  return request<RTS.STREAM.Detail[]>({
    url: `/api/stoppush?url=${url}`,
    method: 'GET'
  })
}

export const createRtspPush = (params: {streamPath: string, target: string, save: number}) => {
  return request<RTS.PullStream.Detail[]>({
    url: '/rtsp/api/push',
    method: 'GET',
    params
  })
}

export const createRtmpPush = (params: {streamPath: string, target: string, save: number}) => {
  return request<RTS.STREAM.Detail[]>({
    url: '/rtsp/api/push',
    method: 'GET',
    params
  })
}

/** 查看存储列表 */
export const getRecordList = (type: 'mp4' | 'ts' | 'flv') => {
  return request<RTS.STREAM.Detail[]>({
    url: `/record/api/list?type=${type}`,
    method: 'GET'
  })
}

/** 正在存储的视频流 */
export const getRecording = () => {
  return request<RTS.STREAM.Detail[]>({
    url: '/record/api/list/recording',
    method: 'GET'
  })
}

/** 开始存储 */
export const postRecord = (params: {type: 'mp4' | 'ts' | 'flv', streamPath: string }) => {
  return request<RTS.STREAM.Detail[]>({
    url: '/record/api/start',
    method: 'GET',
    params
  })
}

/** 停止录制 */
export const stopRecord = (id: string) => {
  return request<RTS.STREAM.Detail[]>({
    url: `/record/api/stop?id=${id}`,
    method: 'GET'
  })
}

/** 录制播放 */
// url: `/record/${id}.${format}`,
export const playRecord = (id: string, format: 'flv'| 'mp4' | 'm3u8' | 'h264'| 'h265') => {
  return request<string>({
    url: `/record/${id}`,
    method: 'GET'
  })
}

/** 获取配置 RTSP */
export const getConfig = (name: 'RTSP' | 'RTMP' | 'HLS' | 'HDL' | 'GB28181') => {
  return request<any>({
    url: `/api/getconfig?name=${name}`,
    method: 'GET'
  })
}

/** 保存配置 RTSP */
export const postConfig = (name: 'RTSP' | 'RTMP' | 'HLS' | 'HDL' | 'GB28181', data: string) => {
  return request<any>({
    url: `/api/modifyconfig?name=${name}`,
    method: 'POST',
    data
  })
}

export const updateConfig = (name: 'RTSP' | 'RTMP' | 'HLS' | 'HDL' | 'GB28181') => {
  return request<string>({
    url: `/api/updateconfig?name=${name}`,
    method: 'GET'
  })
}

/** 系统监控 */
export const getSummary = () => {
  return request<RTS.SUMMARY.Detail>({
    url: '/api/summary',
    method: 'GET'
  })
}

/** 系统监控 流 */
export const getMonitorStream = (params: {time: string, streamPath: string}) => {
  return request<RTS.STREAM.Detail[]>({
    url: '/monitor/api/list/stream',
    method: 'GET',
    params
  })
}

/** 系统监控 轨道 */
export const getMonitorTrack = (params: {time: string, streamPath: string}) => {
  return request<RTS.STREAM.Detail[]>({
    url: '/monitor/api/list/track?streamPath=xxxx',
    method: 'GET',
    params
  })
}

/** 国标设备 */
export const getGB28181Device = () => {
  return request<RTS.GB2881.Detail[]>({
    url: '/gb28181/api/list',
    method: 'GET'
  })
}

/** 国标设备录像 */
export const getGB28181Record = (params: {id: string, channel: string, startTime:string, endTime:string}) => {
  return request<RTS.GB2881.Record[]>({
    url: '/gb28181/api/records',
    method: 'GET',
    params
  })
}

/** 国标设备录像 */
export const controlGB28181 = (params: {id: string, channel: string, ptzcmd:string}) => {
  return request<string>({
    url: '/gb28181/api/control',
    method: 'GET',
    params
  })
}
