import { apiRequest } from '@/shared/api/client'
import type { RoleDto } from '@/shared/api/types'

export function listRoles() {
  return apiRequest<RoleDto[]>('/admin/roles')
}

export function createRole(name: string) {
  return apiRequest<RoleDto>('/admin/roles', { method: 'POST', body: { name } })
}

export function updateRole(id: string, name: string) {
  return apiRequest<RoleDto>(`/admin/roles/${id}`, { method: 'PUT', body: { name } })
}

export function deleteRole(id: string) {
  return apiRequest<void>(`/admin/roles/${id}`, { method: 'DELETE' })
}

export function changeUserRole(userId: string, roleId: string) {
  return apiRequest<void>(`/admin/users/${userId}/role`, { method: 'PATCH', body: { roleId } })
}
