import { apiFetch } from './client'; export interface CrmTask { task_id: string; tenant_id: string; location_id?: string; title: string; description?: string; assignee_id?: string; entity_type?: string; entity_id?: string; priority: 'HIGH' | 'MEDIUM' | 'LOW' | string; status: 'PENDING' | 'COMPLETED' | string; due_at?: string; completed_at?: string; created_at?: string; updated_at?: string; } export interface CrmCalendarEvent { event_id: string; tenant_id: string; location_id?: string; task_id?: string; title: string; description?: string; source_type?: string; source_id?: string; start_time: string; end_time: string; is_all_day?: boolean; status: 'SCHEDULED' | 'COMPLETED' | 'CANCELLED' | string; created_at?: string; updated_at?: string; } export const crmTaskCalendarService = { // --- TASKS --- getTasks: async (params?: { location_id?: string; status?: string; assignee_id?: string; entity_type?: string; entity_id?: string }) => { const queryParams = new URLSearchParams(); if (params?.location_id) queryParams.append('location_id', params.location_id); if (params?.status) queryParams.append('status', params.status); if (params?.assignee_id) queryParams.append('assignee_id', params.assignee_id); if (params?.entity_type) queryParams.append('entity_type', params.entity_type); if (params?.entity_id) queryParams.append('entity_id', params.entity_id); const query = queryParams.toString() ? `?${queryParams.toString()}` : ''; return apiFetch(`/api/v1/crm/tasks${query}`); }, createTask: async (data: Partial) => { return apiFetch('/api/v1/crm/tasks', { method: 'POST', body: JSON.stringify(data), }); }, updateTask: async (taskId: string, data: Partial) => { return apiFetch(`/api/v1/crm/tasks/${taskId}`, { method: 'PUT', body: JSON.stringify(data), }); }, deleteTask: async (taskId: string) => { return apiFetch<{ message: string }>(`/api/v1/crm/tasks/${taskId}`, { method: 'DELETE', }); }, // --- CALENDAR EVENTS --- getCalendarEvents: async (params?: { location_id?: string; start_from?: string; end_until?: string }) => { const queryParams = new URLSearchParams(); if (params?.location_id) queryParams.append('location_id', params.location_id); if (params?.start_from) queryParams.append('start_from', params.start_from); if (params?.end_until) queryParams.append('end_until', params.end_until); const query = queryParams.toString() ? `?${queryParams.toString()}` : ''; return apiFetch(`/api/v1/crm/calendar${query}`); }, createCalendarEvent: async (data: Partial) => { return apiFetch('/api/v1/crm/calendar', { method: 'POST', body: JSON.stringify(data), }); }, updateCalendarEvent: async (eventId: string, data: Partial) => { return apiFetch(`/api/v1/crm/calendar/${eventId}`, { method: 'PUT', body: JSON.stringify(data), }); }, deleteCalendarEvent: async (eventId: string) => { return apiFetch<{ message: string }>(`/api/v1/crm/calendar/${eventId}`, { method: 'DELETE', }); }, };