import axiosInstance from '@/lib/axios' import type { ApiResponse, LoginResponse } from '@/types/api' /** * Auth API Service */ export const authApi = { /** * Login with email and password */ login: async (email: string, password: string): Promise> => { const response = await axiosInstance.post>('/v1/login', { email, password, }) return response.data }, /** * Logout current user */ logout: async (): Promise> => { const response = await axiosInstance.post>('/v1/logout') return response.data }, /** * Get current user profile */ me: async (): Promise> => { const response = await axiosInstance.get>('/v1/users/me') return response.data }, } /** * Tenant API Service */ export const tenantApi = { /** * Switch to different tenant */ switch: async (tenantId: number): Promise> => { const response = await axiosInstance.post>(`/v1/tenants/${tenantId}/switch`) return response.data }, /** * Get list of tenants for current user */ list: async (): Promise> => { const response = await axiosInstance.get>('/v1/users/me/tenants') return response.data }, } /** * Generic API helper for CRUD operations */ export const createCrudApi = (basePath: string) => ({ list: async (params?: Record): Promise> => { const response = await axiosInstance.get>(basePath, { params }) return response.data }, get: async (id: number | string): Promise> => { const response = await axiosInstance.get>(`${basePath}/${id}`) return response.data }, create: async (data: Partial): Promise> => { const response = await axiosInstance.post>(basePath, data) return response.data }, update: async (id: number | string, data: Partial): Promise> => { const response = await axiosInstance.put>(`${basePath}/${id}`, data) return response.data }, delete: async (id: number | string): Promise> => { const response = await axiosInstance.delete>(`${basePath}/${id}`) return response.data }, })