import apiClient from './api-client'; export interface LoginRequest { email: string; password: string; } export interface User { id: string; email: string; first_name: string; last_name: string; } export interface Permission { resource: string; action: string; } export interface TenantModule { id: string; name: string; } export interface Tenant { id: string; name: string; assignedModules?: TenantModule[]; } export interface LoginResponse { success: boolean; data: { user: User; tenant_id: string; // tenant: Tenant; roles: string[]; permissions: Permission[]; access_token: string; refresh_token: string; token_type: string; expires_in: number; expires_at: string; }; message?: string; } export interface ValidationError { success: false; error: 'Validation failed'; details: Array<{ path: string; message: string; code: string; }>; } export interface GeneralError { success: false; error: { code: string; message: string; }; } export type LoginError = ValidationError | GeneralError; export interface LogoutResponse { success: boolean; message?: string; } export interface ForgotPasswordRequest { email: string; } export interface ForgotPasswordResponse { success: boolean; data: { success: boolean; message: string; }; } export interface ResetPasswordRequest { token: string; password: string; } export interface ResetPasswordResponse { success: boolean; data?: { message?: string; }; message?: string; } export interface RefreshTokenRequest { refresh_token: string; } export interface RefreshTokenResponse { success: boolean; data: { access_token: string; refresh_token: string; token_type: string; expires_in: number; expires_at: string; }; } export const authService = { login: async (credentials: LoginRequest): Promise => { const response = await apiClient.post('/auth/login', credentials); return response.data; }, logout: async (): Promise => { // Token will be automatically added by api-client interceptor const response = await apiClient.post('/auth/logout', {}); return response.data; }, forgotPassword: async (data: ForgotPasswordRequest): Promise => { const response = await apiClient.post('/auth/forgot-password', data); return response.data; }, resetPassword: async (data: ResetPasswordRequest): Promise => { const response = await apiClient.post('/auth/reset-password', data); return response.data; }, refreshToken: async (data: RefreshTokenRequest): Promise => { const response = await apiClient.post('/auth/refresh', data); return response.data; }, };