import apiClient from './client'
import type {
  UserCreateRequest,
  UserListResponse,
  UserResponse,
  UserUpdateRequest,
} from '@/types/api.types'

export const usersApi = {
  list: (page = 1, page_size = 25) =>
    apiClient
      .get<UserListResponse>('/users', { params: { page, page_size } })
      .then((r) => r.data),

  get: (id: string) =>
    apiClient.get<UserResponse>(`/users/${id}`).then((r) => r.data),

  create: (data: UserCreateRequest) =>
    apiClient.post<UserResponse>('/users', data).then((r) => r.data),

  update: (id: string, data: UserUpdateRequest) =>
    apiClient.patch<UserResponse>(`/users/${id}`, data).then((r) => r.data),

  delete: (id: string) => apiClient.delete(`/users/${id}`),

  resetPassword: (id: string, new_password: string) =>
    apiClient.post(`/users/${id}/reset-password`, { new_password }),
}
