/**
 * Sensor Hub Service
 * Handles sensor hub API calls
 */

import { apiClient } from '../client'

export interface Sensor {
  name: string
  uuid_sensor: string
  last_updated: string
  [key: string]: unknown
}

export interface ListSensorsResponse {
  status?: string
  data: Sensor | Sensor[]
}

export const sensorHubService = {
  /**
   * Get list of sensors
   */
  async listSensors(): Promise<Sensor[]> {
    const response = await apiClient.get<ListSensorsResponse>('/api/sensor-hub/')
    const data = response?.data

    if (Array.isArray(data)) {
      return data
    }

    if (data && typeof data === 'object') {
      return [data as Sensor]
    }

    return []
  }
}
