import { useMutation, useQueryClient } from '@tanstack/react-query'
import { createRole } from '../api/createRole'
import type { CreateRolRequest } from '../api/types'
import { rolesQueryKey } from './useRoles'

export function useCreateRole() {
  const qc = useQueryClient()
  return useMutation({
    mutationFn: (payload: CreateRolRequest) => createRole(payload),
    onSuccess: () => {
      void qc.invalidateQueries({ queryKey: rolesQueryKey })
    },
  })
}
