import {z} from 'zod' export type UpdateApiV1TimeOffPoliciesTimeOffPolicyUuidArgs = {'X-Gusto-API-Version'?: '2026-06-15' | undefined, time_off_policy_uuid: string, body: {version: string, name?: string | undefined, policy_type?: ('vacation' | 'sick') | undefined, accrual_method?: ('unlimited' | 'per_pay_period' | 'per_calendar_year' | 'per_anniversary_year' | 'per_hour_worked' | 'per_hour_worked_no_overtime' | 'per_hour_paid' | 'per_hour_paid_no_overtime') | undefined, accrual_rate?: (string | null) | undefined, accrual_rate_unit?: (string | null) | undefined, paid_out_on_termination?: boolean | undefined, accrual_waiting_period_days?: (number | null) | undefined, carryover_limit_hours?: (string | null) | undefined, max_accrual_hours_per_year?: (string | null) | undefined, max_hours?: (string | null) | undefined, policy_reset_date?: (string | null) | undefined, complete?: boolean | undefined}}; export type UpdateApiV1TimeOffPoliciesTimeOffPolicyUuidOptions = {baseUrl?: string | undefined, CompanyAccessAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const timeOffPolicy = z.object({uuid: z.string(), company_uuid: z.string(), name: z.string(), policy_type: z.enum(["vacation", "sick", "bereavement", "custom", "floating_holiday", "jury_duty", "learning_and_development", "parental_leave", "personal_day", "volunteer", "weather"]), accrual_method: z.string(), accrual_rate: z.string().nullable().optional(), accrual_rate_unit: z.string().nullable().optional(), paid_out_on_termination: z.boolean().optional(), accrual_waiting_period_days: z.number().int().nullable().optional(), carryover_limit_hours: z.string().nullable().optional(), max_accrual_hours_per_year: z.string().nullable().optional(), max_hours: z.string().nullable().optional(), policy_reset_date: z.string().nullable().optional(), complete: z.boolean().optional(), version: z.string().nullable().optional(), is_active: z.boolean(), employees: z.array(z.object({uuid: z.string().optional(), balance: z.string().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 time off policy * * PUT /v1/time_off_policies/{time_off_policy_uuid} */ export const updateApiV1TimeOffPoliciesTimeOffPolicyUuid = async (args: UpdateApiV1TimeOffPoliciesTimeOffPolicyUuidArgs, options?: UpdateApiV1TimeOffPoliciesTimeOffPolicyUuidOptions) => { 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/time_off_policies/${encodeURIComponent(String(args.time_off_policy_uuid))}${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(timeOffPolicy, await res.json()) };