import {z} from 'zod' export type GarnishmentChildSupport = {state?: string | undefined, payment_period?: ('Every week' | 'Every other week' | 'Twice per month' | 'Monthly') | undefined, fips_code?: string | undefined, case_number?: (string | null) | undefined, order_number?: (string | null) | undefined, remittance_number?: (string | null) | undefined} | null; export type UpdateGarnishmentRequest = {active?: boolean | undefined, amount?: unknown | undefined, description?: string | undefined, court_ordered?: boolean | undefined, garnishment_type?: ('child_support' | 'federal_tax_lien' | 'state_tax_lien' | 'student_loan' | 'creditor_garnishment' | 'federal_loan' | 'other_garnishment' | null) | undefined, times?: (number | null) | undefined, recurring?: boolean | undefined, annual_maximum?: (unknown | null) | undefined, pay_period_maximum?: (unknown | null) | undefined, deduct_as_percentage?: boolean | undefined, total_amount?: (unknown | null) | undefined, child_support?: GarnishmentChildSupport | undefined, version: string}; export type UpdateApiV1GarnishmentsGarnishmentIdArgs = {'X-Gusto-API-Version'?: '2026-06-15' | undefined, garnishment_id: string, body: UpdateGarnishmentRequest}; export type UpdateApiV1GarnishmentsGarnishmentIdOptions = {baseUrl?: string | undefined, CompanyAccessAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const garnishmentChildSupport = z.object({state: z.string().optional(), payment_period: z.enum(["Every week", "Every other week", "Twice per month", "Monthly"]).optional(), fips_code: z.string().optional(), case_number: z.string().nullable().optional(), order_number: z.string().nullable().optional(), remittance_number: z.string().nullable().optional()}).nullable(); export const garnishment = z.object({uuid: z.string(), version: z.string().optional(), employee_uuid: z.string().optional(), active: z.boolean().optional(), amount: z.string().optional(), description: z.string().optional(), court_ordered: z.boolean().optional(), times: z.number().int().nullable().optional(), recurring: z.boolean().optional(), annual_maximum: z.string().nullable().optional(), total_amount: z.string().nullable().optional(), pay_period_maximum: z.string().nullable().optional(), deduct_as_percentage: z.boolean().optional(), garnishment_type: z.enum(["child_support", "federal_tax_lien", "state_tax_lien", "student_loan", "creditor_garnishment", "federal_loan", "other_garnishment"]).nullable().optional(), child_support: garnishmentChildSupport.optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update a garnishment * * PUT /v1/garnishments/{garnishment_id} */ export const updateApiV1GarnishmentsGarnishmentId = async (args: UpdateApiV1GarnishmentsGarnishmentIdArgs, options?: UpdateApiV1GarnishmentsGarnishmentIdOptions) => { const {baseUrl = "https://api.gusto-demo.com", fetch: fetchFn = fetch, CompanyAccessAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Gusto-API-Version'] != null) headers.set("X-Gusto-API-Version", String(args['X-Gusto-API-Version'])) if (CompanyAccessAuth !== undefined) headers.set('authorization', `Bearer ${CompanyAccessAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/garnishments/${encodeURIComponent(String(args.garnishment_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(garnishment, await res.json()) };