// Caminho: services/agendamentosApi.ts (Completo, com adição de update e delete) import api from './api'; export interface Appointment { id: string; doctor_id: string; patient_id: string; scheduled_at: string; duration_minutes?: number; status: 'requested' | 'confirmed' | 'completed' | 'cancelled'; created_by?: string; cancel_reason?: string; reschedule_reason?: string; appointment_type?: 'presencial' | 'telemedicina'; notes?: string; doctors?: { full_name: string; specialty: string; }; } export type CreateAppointmentData = Omit; export type UpdateAppointmentData = Partial>; export interface AvailableSlot { time: string; available: boolean; } export const agendamentosApi = { listByPatient: async (patientId: string): Promise => { const response = await api.get('/rest/v1/appointments', { params: { patient_id: `eq.${patientId}`, select: '*,doctors(full_name,specialty)', order: 'scheduled_at.asc', }, }); return response.data; }, create: async (data: CreateAppointmentData): Promise => { const response = await api.post('/rest/v1/appointments', data, { headers: { 'Prefer': 'return=representation' }, }); return response.data[0]; }, /** * Atualiza um agendamento existente (PATCH). * @param id - O UUID do agendamento. * @param data - Os campos a serem atualizados. */ update: async (id: string, data: UpdateAppointmentData): Promise => { const response = await api.patch(`/rest/v1/appointments?id=eq.${id}`, data, { headers: { 'Prefer': 'return=representation', }, }); return response.data[0]; }, /** * Exclui um agendamento. * @param id - O UUID do agendamento a ser excluído. */ delete: async (id: string): Promise => { await api.delete(`/rest/v1/appointments?id=eq.${id}`); }, getAvailableSlots: async (doctorId: string, date: string): Promise<{ slots: AvailableSlot[] }> => { const response = await api.post<{ slots: AvailableSlot[] }>('/functions/v1/get-available-slots', { doctor_id: doctorId, date: date, }); return response.data; }, getMockAppointments: async (): Promise => { const response = await api.get('https://mock.apidog.com/m1/1053378-0-default/rest/v1/doctors'); return response.data.map((doctor: any, index: number) => ({ id: `mock-${index + 1}`, doctor_id: doctor.id || `doc-mock-${index + 1}`, patient_id: 'patient-mock-1', scheduled_at: new Date(Date.now() + 86400000 * (index + 2)).toISOString(), status: index % 2 === 0 ? 'confirmed' : 'requested', appointment_type: index % 2 === 0 ? 'presencial' : 'telemedicina', doctors: { full_name: doctor.full_name || `Dr. Exemplo ${index + 1}`, specialty: doctor.specialty || 'Especialidade', }, })); }, };