import apiClient from './client'
import type {
  PermissionPresetCreate,
  PermissionPresetResponse,
  PermissionPresetUpdate,
} from '@/types/api.types'

export const permissionPresetsApi = {
  /**
   * Lista tutti i preset del tenant corrente.
   */
  list: () =>
    apiClient
      .get<PermissionPresetResponse[]>('/permission-presets')
      .then((r) => r.data),

  /**
   * Crea un nuovo preset.
   */
  create: (data: PermissionPresetCreate) =>
    apiClient
      .post<PermissionPresetResponse>('/permission-presets', data)
      .then((r) => r.data),

  /**
   * Aggiorna un preset esistente.
   */
  update: (id: string, data: PermissionPresetUpdate) =>
    apiClient
      .put<PermissionPresetResponse>(`/permission-presets/${id}`, data)
      .then((r) => r.data),

  /**
   * Elimina un preset.
   */
  delete: (id: string) =>
    apiClient.delete(`/permission-presets/${id}`),
}
