
import request from '@/service/request'

export const getSpace = (params: COMMON.API.QueryParams) => {
  return request<CVS.space[]>({
    url: '/space/page',
    method: 'GET',
    params
  })
}

export const getSpaceList = (spaceName: string, limit: number) => {
  return request<CVS.space[]>({
    url: `/space/list?spaceName=${spaceName}&limit=${limit}`,
    method: 'GET'
  })
}

export const addSpace = (data: Partial<CVS.space>) => {
  return request<string>({
    url: '/space',
    method: 'POST',
    data
  })
}

export const updateSpace = (data: CVS.space) => {
  return request<string>({
    url: '/spaceConfig',
    method: 'PUT',
    data
  })
}

export const getSpaceConfigById = (spaceId: string) => {
  return request<CVS.space>({
    url: `/spaceConfig/${spaceId}`,
    method: 'GET'
  })
}

export const getSpaceById = (spaceId: string) => {
  return request<CVS.space>({
    url: `/space/${spaceId}`,
    method: 'GET'
  })
}

export const delSpace = (id: string) => {
  return request<string>({
    url: `/space?id=${id}`,
    method: 'DELETE'
  })
}
// /space/status?spaceId=xx&status=xxx
export const updateStatus = (spaceId, status) => {
  return request<string>({
    url: `/space/status?spaceId=${spaceId}&status=${status}`,
    method: 'PUT'
  })
}

export const getDevicePage = (params: COMMON.API.QueryParams & {deviceName: string}) => {
  return request<CVS.device[]>({
    url: '/device/page',
    method: 'GET',
    params
  })
}

// export const getDeviceList = (params: COMMON.API.QueryParams & {deviceName: string}) => {
//   return request<CVS.device[]>({
//     url: '/device/list?deviceName=xxxx',
//     method: 'GET',
//     params
//   })
// }

export const getDeviceById = (deviceId: string) => {
  return request<CVS.device>({
    url: `/device/${deviceId}`,
    method: 'GET'
  })
}

export const addDevice = (data: Partial<CVS.device>) => {
  return request<string>({
    url: '/device',
    method: 'POST',
    data
  })
}

export const getDeviceRecordById = (params: {
  deviceId: string
  startTs?: number,
  endTs?: number,
  recordFormat: 'FLV' | 'TS' | 'MP4' | 'RAW'
}) => {
  return request<{
    deviceId: string
    recordFormat: 'FLV' | 'TS' | 'MP4' | 'RAW'
    recordStartTs: number
    recordEndTs: number
    recordUrl: string
  }>({
    url: `/device/record/${params.deviceId}`,
    method: 'GET',
    params
  })
}

export const getDeviceThumbById = (params: {
  deviceId: string
  startTs?: number,
  endTs?: number
}) => {
  return request<{
    deviceId: string
    thumbTs: number
    thumbUrl: string
  }>({
    url: `/device/thumb/${params.deviceId}`,
    method: 'GET',
    params
  })
}

export const getDeviceAiRetById = (params: {
  deviceId: string
  startTs?: number,
  endTs?: number
  aiId?: string
}) => {
  return request<{
    deviceId: string
    aiId: string
    aiDesc: string
    aiRetType: 'IMG' | 'VIDEO' | 'TXT'
    aiRetUrl: string
    aiTs: number
  }>({
    url: `/device/aiRet/${params.deviceId}`,
    method: 'GET',
    params
  })
}
