/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { MutationKey, useMutation, UseMutationResult, } from "@tanstack/react-query"; import { GustoEmbeddedCore } from "../core.js"; import { departmentsDelete } from "../funcs/departmentsDelete.js"; import { combineSignals } from "../lib/primitives.js"; import { RequestOptions } from "../lib/sdks.js"; import { GustoEmbeddedError } from "../models/errors/gustoembeddederror.js"; import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError, } from "../models/errors/httpclienterrors.js"; import { NotFoundErrorObject } from "../models/errors/notfounderrorobject.js"; import { ResponseValidationError } from "../models/errors/responsevalidationerror.js"; import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; import { UnprocessableEntityError } from "../models/errors/unprocessableentityerror.js"; import { DeleteDepartmentRequest, DeleteDepartmentResponse, } from "../models/operations/deletedepartment.js"; import { unwrapAsync } from "../types/fp.js"; import { useGustoEmbeddedContext } from "./_context.js"; import { MutationHookOptions } from "./_types.js"; export type DepartmentsDeleteMutationVariables = { request: DeleteDepartmentRequest; options?: RequestOptions; }; export type DepartmentsDeleteMutationData = DeleteDepartmentResponse; export type DepartmentsDeleteMutationError = | NotFoundErrorObject | UnprocessableEntityError | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError; /** * Delete a department * * @remarks * Delete a department. You cannot delete a department until all employees and contractors have been removed. * * scope: `departments:write` */ export function useDepartmentsDeleteMutation( options?: MutationHookOptions< DepartmentsDeleteMutationData, DepartmentsDeleteMutationError, DepartmentsDeleteMutationVariables >, ): UseMutationResult< DepartmentsDeleteMutationData, DepartmentsDeleteMutationError, DepartmentsDeleteMutationVariables > { const client = useGustoEmbeddedContext(); return useMutation({ ...buildDepartmentsDeleteMutation(client, options), ...options, }); } export function mutationKeyDepartmentsDelete(): MutationKey { return ["@gusto/embedded-api", "Departments", "delete"]; } export function buildDepartmentsDeleteMutation( client$: GustoEmbeddedCore, hookOptions?: RequestOptions, ): { mutationKey: MutationKey; mutationFn: ( variables: DepartmentsDeleteMutationVariables, ) => Promise; } { return { mutationKey: mutationKeyDepartmentsDelete(), mutationFn: function departmentsDeleteMutationFn({ request, options, }): Promise { const mergedOptions = { ...hookOptions, ...options, fetchOptions: { ...hookOptions?.fetchOptions, ...options?.fetchOptions, signal: combineSignals( hookOptions?.fetchOptions?.signal, options?.fetchOptions?.signal, ), }, }; return unwrapAsync(departmentsDelete( client$, request, mergedOptions, )); }, }; }