import type { AdminUser } from '@/entities/user/model/types'
import { apiClient } from '@/shared/api/client'

export type AdminUsersListResponse = {
  items: AdminUser[]
  total: number
  page: number
  pageSize: number
}

export async function fetchAdminUsers(params?: {
  q?: string
  page?: number
  pageSize?: number
}): Promise<AdminUsersListResponse> {
  const { data } = await apiClient.get<AdminUsersListResponse>('admin/users', { params })
  return data
}

export async function createAdminUser(body: { email: string; name?: string | null }): Promise<AdminUser> {
  const { data } = await apiClient.post<AdminUser>('admin/users', body)
  return data
}

export async function updateAdminUser(
  id: string,
  body: Partial<{ email: string; name: string | null }>,
): Promise<AdminUser> {
  const { data } = await apiClient.patch<AdminUser>(`admin/users/${id}`, body)
  return data
}

export async function deleteAdminUser(id: string): Promise<void> {
  await apiClient.delete(`admin/users/${id}`)
}
