export interface EmailRequest { id: number; recipient: string; email: string; status: string; createdAt: string; updatedAt: string; } export interface CreateEmailRequestDto { email: string; status?: string; } export interface UpdateEmailRequestDto { email?: string; status?: string; } const API_BASE = process.env.NEXT_PUBLIC_API_BASE_URL || ''; export async function fetchEmailRequests(token: string): Promise { const response = await fetch(`${API_BASE}/api/email`, { headers: { Authorization: `Bearer ${token}`, }, }); if (!response.ok) { throw new Error(`Failed to fetch email requests: ${response.statusText}`); } return response.json(); } export async function createEmailRequest(token: string, data: CreateEmailRequestDto): Promise { const response = await fetch(`${API_BASE}/api/email`, { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}`, }, body: JSON.stringify(data), }); if (!response.ok) { throw new Error(`Failed to create email request: ${response.statusText}`); } return response.json(); } export async function updateEmailRequest(token: string, id: number, data: UpdateEmailRequestDto): Promise { const response = await fetch(`${API_BASE}/api/email/${id}`, { method: 'PUT', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}`, }, body: JSON.stringify(data), }); if (!response.ok) { throw new Error(`Failed to update email request: ${response.statusText}`); } return response.json(); } export async function deleteEmailRequest(token: string, id: number): Promise { const response = await fetch(`${API_BASE}/api/email/${id}`, { method: 'DELETE', headers: { Authorization: `Bearer ${token}`, }, }); if (!response.ok) { throw new Error(`Failed to delete email request: ${response.statusText}`); } }