/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { MutationKey, useMutation, UseMutationResult, } from "@tanstack/react-query"; import { GustoEmbeddedCore } from "../core.js"; import { garnishmentsCreate } from "../funcs/garnishmentsCreate.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 { PostV1EmployeesEmployeeIdGarnishmentsRequest, PostV1EmployeesEmployeeIdGarnishmentsResponse, } from "../models/operations/postv1employeesemployeeidgarnishments.js"; import { unwrapAsync } from "../types/fp.js"; import { useGustoEmbeddedContext } from "./_context.js"; import { MutationHookOptions } from "./_types.js"; export type GarnishmentsCreateMutationVariables = { request: PostV1EmployeesEmployeeIdGarnishmentsRequest; options?: RequestOptions; }; export type GarnishmentsCreateMutationData = PostV1EmployeesEmployeeIdGarnishmentsResponse; export type GarnishmentsCreateMutationError = | NotFoundErrorObject | UnprocessableEntityError | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError; /** * Create a garnishment * * @remarks * Garnishments, or employee deductions, are fixed amounts or percentages deducted from an employee’s pay. They can be deducted a specific number of times or on a recurring basis. Garnishments can also have maximum deductions on a yearly or per-pay-period bases. Common uses for garnishments are court-ordered payments for child support or back taxes. Some companies provide loans to their employees that are repaid via garnishments. * * scope: `garnishments:write` */ export function useGarnishmentsCreateMutation( options?: MutationHookOptions< GarnishmentsCreateMutationData, GarnishmentsCreateMutationError, GarnishmentsCreateMutationVariables >, ): UseMutationResult< GarnishmentsCreateMutationData, GarnishmentsCreateMutationError, GarnishmentsCreateMutationVariables > { const client = useGustoEmbeddedContext(); return useMutation({ ...buildGarnishmentsCreateMutation(client, options), ...options, }); } export function mutationKeyGarnishmentsCreate(): MutationKey { return ["@gusto/embedded-api", "Garnishments", "create"]; } export function buildGarnishmentsCreateMutation( client$: GustoEmbeddedCore, hookOptions?: RequestOptions, ): { mutationKey: MutationKey; mutationFn: ( variables: GarnishmentsCreateMutationVariables, ) => Promise; } { return { mutationKey: mutationKeyGarnishmentsCreate(), mutationFn: function garnishmentsCreateMutationFn({ request, options, }): Promise { const mergedOptions = { ...hookOptions, ...options, fetchOptions: { ...hookOptions?.fetchOptions, ...options?.fetchOptions, signal: combineSignals( hookOptions?.fetchOptions?.signal, options?.fetchOptions?.signal, ), }, }; return unwrapAsync(garnishmentsCreate( client$, request, mergedOptions, )); }, }; }