// Funktion zum Laden der Clients von der API

export interface Client {
  uuid: string;
  location: string;
  hardware_hash: string;
  ip_address: string;
  last_alive: string | null;
  group_id: number; // <--- Dieses Feld ergänzen
}

export async function fetchClients(): Promise<Client[]> {
  const response = await fetch('/api/clients');
  if (!response.ok) {
    throw new Error('Fehler beim Laden der Clients');
  }
  return await response.json();
}

export async function updateClientGroup(clientIds: string[], groupName: string) {
  const res = await fetch('/api/clients/group', {
    method: 'PUT',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ client_ids: clientIds, group_name: groupName }),
  });
  if (!res.ok) throw new Error('Fehler beim Aktualisieren der Clients');
  return await res.json();
}
