import { Employee, CreateEmployeeRequest, UpdateEmployeeRequest, EmployeeAvailability } from '../models/Employee'; import { apiClient } from './apiClient'; export class EmployeeService { async getEmployees(includeInactive: boolean = false): Promise { console.log('🔄 Fetching employees from API...'); try { const employees = await apiClient.get(`/employees?includeInactive=${includeInactive}`); console.log('✅ Employees received:', employees.length); return employees; } catch (error) { console.error('❌ Error fetching employees:', error); throw error; // Let useBackendValidation handle this } } async getEmployee(id: string): Promise { return apiClient.get(`/employees/${id}`); } async createEmployee(employee: CreateEmployeeRequest): Promise { return apiClient.post('/employees', employee); } async updateEmployee(id: string, employee: UpdateEmployeeRequest): Promise { return apiClient.put(`/employees/${id}`, employee); } async deleteEmployee(id: string): Promise { await apiClient.delete(`/employees/${id}`); } async getAvailabilities(employeeId: string): Promise { return apiClient.get(`/employees/${employeeId}/availabilities`); } async updateAvailabilities( employeeId: string, data: { planId: string, availabilities: Omit[] } ): Promise { console.log('🔄 Updating availabilities for employee:', employeeId); return apiClient.put(`/employees/${employeeId}/availabilities`, data); } async changePassword( id: string, data: { currentPassword: string, newPassword: string, confirmPassword: string } ): Promise { return apiClient.put(`/employees/${id}/password`, data); } async updateLastLogin(employeeId: string): Promise { try { await apiClient.patch(`/employees/${employeeId}/last-login`); } catch (error) { console.error('Error updating last login:', error); throw error; } } } export const employeeService = new EmployeeService();