export interface Task { id: number; title: string; description: string; status: "pending" | "in_progress" | "completed"; priority: "low" | "medium" | "high"; createdAt: string; updatedAt: string; } export interface APIResponse { success: boolean; data?: T; error?: string; } const API_BASE = "/api"; export async function fetchTasks(): Promise { const res = await fetch(`${API_BASE}/tasks`); const json: APIResponse = await res.json(); if (!json.success) throw new Error(json.error || "Failed to fetch tasks"); return json.data || []; } export async function fetchTask(id: number): Promise { const res = await fetch(`${API_BASE}/tasks/${id}`); const json: APIResponse = await res.json(); if (!json.success) throw new Error(json.error || "Failed to fetch task"); return json.data!; } export async function createTask( task: Pick ): Promise { const res = await fetch(`${API_BASE}/tasks`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(task), }); const json: APIResponse = await res.json(); if (!json.success) throw new Error(json.error || "Failed to create task"); return json.data!; } export async function deleteTask(id: number): Promise { const res = await fetch(`${API_BASE}/tasks/${id}`, { method: "DELETE", }); const json: APIResponse = await res.json(); if (!json.success) throw new Error(json.error || "Failed to delete task"); }