import {z} from 'zod' export type PayScheduleAssignmentBody = {type: 'single' | 'hourly_salaried' | 'by_employee' | 'by_department' | null, hourly_pay_schedule_uuid?: string | undefined, salaried_pay_schedule_uuid?: string | undefined, default_pay_schedule_uuid?: string | undefined, partial_assignment?: boolean | undefined, employees?: (Array<{employee_uuid?: string | undefined, pay_schedule_uuid?: string | undefined}>) | undefined, departments?: (Array<{department_uuid?: string | undefined, pay_schedule_uuid?: string | undefined}>) | undefined}; export type CreateApiV1CompaniesCompanyIdPaySchedulesAssignmentPreviewArgs = {'X-Gusto-API-Version'?: '2026-06-15' | undefined, company_id: string, body: PayScheduleAssignmentBody}; export type CreateApiV1CompaniesCompanyIdPaySchedulesAssignmentPreviewOptions = {baseUrl?: string | undefined, CompanyAccessAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const payScheduleAssignmentPayPeriod = z.object({pay_schedule_uuid: z.string().optional(), start_date: z.string().optional(), end_date: z.string().optional(), check_date: z.string().optional()}); export const payScheduleAssignmentTransitionPayPeriod = z.object({start_date: z.string().optional(), end_date: z.string().optional()}); export const payScheduleAssignmentEmployeeChange = z.object({employee_uuid: z.string().optional(), first_name: z.string().optional(), last_name: z.string().optional(), pay_frequency: z.string().optional(), first_pay_period: payScheduleAssignmentPayPeriod.optional(), transition_pay_period: payScheduleAssignmentTransitionPayPeriod.optional()}); export const payScheduleAssignmentPreview = z.object({type: z.enum(["single", "hourly_salaried", "by_employee", "by_department"]).nullable().optional(), employee_changes: z.array(payScheduleAssignmentEmployeeChange).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 }; /** * Preview pay schedule assignments for a company * * POST /v1/companies/{company_id}/pay_schedules/assignment_preview */ export const createApiV1CompaniesCompanyIdPaySchedulesAssignmentPreview = async (args: CreateApiV1CompaniesCompanyIdPaySchedulesAssignmentPreviewArgs, options?: CreateApiV1CompaniesCompanyIdPaySchedulesAssignmentPreviewOptions) => { 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/companies/${encodeURIComponent(String(args.company_id))}/pay_schedules/assignment_preview${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(payScheduleAssignmentPreview, await res.json()) };