import {z} from 'zod' export type GetApiV1EmployeesEmployeeIdGarnishmentsArgs = {'X-Gusto-API-Version'?: '2026-06-15' | undefined, employee_id: string, page?: number | undefined, per?: number | undefined}; export type GetApiV1EmployeesEmployeeIdGarnishmentsOptions = {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 getApiV1EmployeesEmployeeIdGarnishmentsResponse = z.array(garnishment); 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 }; /** * Get garnishments for an employee * * GET /v1/employees/{employee_id}/garnishments */ export const getApiV1EmployeesEmployeeIdGarnishments = async (args: GetApiV1EmployeesEmployeeIdGarnishmentsArgs, options?: GetApiV1EmployeesEmployeeIdGarnishmentsOptions) => { const {baseUrl = "https://api.gusto-demo.com", fetch: fetchFn = fetch, CompanyAccessAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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 (args.page != null) query.append("page", String(args.page)) if (args.per != null) query.append("per", String(args.per)) if (CompanyAccessAuth !== undefined) headers.set('authorization', `Bearer ${CompanyAccessAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/employees/${encodeURIComponent(String(args.employee_id))}/garnishments${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1EmployeesEmployeeIdGarnishmentsResponse, await res.json()) };