import client from '../client';
import type { PaginatedResponse } from '../types';

// --- Types ---
export interface DeviceItem {
  id: string;
  patient_id: string;
  device_id: string;
  device_model: string;
  device_type: string;
  status?: string;
  firmware_version?: string;
  manufacturer?: string;
  connection_type?: string;
  metadata?: Record<string, unknown>;
  bound_at: string;
  last_sync_at: string;
  version: number;
}

// --- API ---
export const deviceApi = {
  listDevices: (params?: {
    patient_id?: string;
    device_type?: string;
    page?: number;
    page_size?: number;
  }) =>
    client
      .get('/health/devices', { params })
      .then((r) => r.data.data as PaginatedResponse<DeviceItem>),

  unbindDevice: (id: string, version: number) =>
    client
      .delete(`/health/devices/${id}`, { data: { version } })
      .then((r) => r.data.data as DeviceItem),
};
