import { BaseApiClient } from '../base/BaseApiClient'; import type { UserDto, UserListResponse, ListUsersQuery, DashboardStats } from '@/lib/types/admin'; /** * Admin API Client * * Provides methods for admin operations like user management. * Only accessible to users with Owner or Super Admin roles. */ export class AdminApiClient extends BaseApiClient { /** * List all users with filtering, sorting, and pagination * Requires Owner or Super Admin role */ async listUsers(query: ListUsersQuery = {}): Promise { const params = new URLSearchParams(); if (query.role) params.append('role', query.role); if (query.status) params.append('status', query.status); if (query.email) params.append('email', query.email); if (query.search) params.append('search', query.search); if (query.page) params.append('page', query.page.toString()); if (query.limit) params.append('limit', query.limit.toString()); if (query.sortBy) params.append('sortBy', query.sortBy); if (query.sortDirection) params.append('sortDirection', query.sortDirection); return this.get(`/admin/users?${params.toString()}`); } /** * Get a single user by ID * Requires Owner or Super Admin role */ async getUser(userId: string): Promise { return this.get(`/admin/users/${userId}`); } /** * Update user roles * Requires Owner role only */ async updateUserRoles(userId: string, roles: string[]): Promise { return this.patch(`/admin/users/${userId}/roles`, { roles }); } /** * Update user status (activate/suspend/delete) * Requires Owner or Super Admin role */ async updateUserStatus(userId: string, status: string): Promise { return this.patch(`/admin/users/${userId}/status`, { status }); } /** * Delete a user (soft delete) * Requires Owner or Super Admin role */ async deleteUser(userId: string): Promise { return this.delete(`/admin/users/${userId}`); } /** * Create a new user * Requires Owner or Super Admin role */ async createUser(userData: { email: string; displayName: string; roles: string[]; primaryDriverId?: string; }): Promise { return this.post(`/admin/users`, userData); } /** * Get dashboard statistics * Requires Owner or Super Admin role */ async getDashboardStats(): Promise { return this.get(`/admin/dashboard/stats`); } }