const API_URL = 'http://localhost:5000/api'; export interface Vehicle { vin: string; status: string; currentVersion: string; lastHeartbeat: string; groupId?: number; group?: VehicleGroup; } export interface VehicleGroup { id: number; name: string; description?: string; vehicles?: Vehicle[]; } export interface FirmwareUpdate { id: number; version: string; description?: string; uploadedAt: string; } export interface Deployment { id: number; updateId: number; targetVin?: string; targetGroupId?: number; status: string; createdAt: string; update: FirmwareUpdate; } export async function fetchVehicles(): Promise { const res = await fetch(`${API_URL}/admin/vehicles`); if (!res.ok) throw new Error('Failed to fetch vehicles'); return res.json(); } export async function fetchGroups(): Promise { const res = await fetch(`${API_URL}/admin/groups`); if (!res.ok) throw new Error('Failed to fetch groups'); return res.json(); } export async function getUpdates(): Promise { const res = await fetch(`${API_URL}/admin/updates`); if (!res.ok) throw new Error('Failed to fetch updates'); return res.json(); } export async function createGroup(name: string, description?: string): Promise { const res = await fetch(`${API_URL}/admin/groups`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name, description }), }); if (!res.ok) throw new Error('Failed to create group'); return res.json(); } export async function updateGroup(id: number, name: string, description?: string): Promise { const res = await fetch(`${API_URL}/admin/groups/${id}`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name, description }), }); if (!res.ok) throw new Error('Failed to update group'); return res.json(); } export async function assignVehicleToGroup(groupId: number, vin: string): Promise { const res = await fetch(`${API_URL}/admin/groups/${groupId}/vehicles`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ vin }), }); if (!res.ok) throw new Error('Failed to assign vehicle to group'); } export async function fetchDeployments(): Promise { const res = await fetch(`${API_URL}/admin/deployments`); if (!res.ok) throw new Error('Failed to fetch deployments'); return res.json(); } export async function uploadUpdate(formData: FormData): Promise { const res = await fetch(`${API_URL}/admin/updates`, { method: 'POST', body: formData, }); if (!res.ok) throw new Error('Failed to upload update'); } export async function createDeployment(updateId: number, targetVin?: string, targetGroupId?: number): Promise { const res = await fetch(`${API_URL}/admin/deployments`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ updateId, targetVin, targetGroupId }), }); if (!res.ok) throw new Error('Failed to create deployment'); }