import {z} from 'zod' export type CreateApiV1CompaniesCompanyIdContractorPaymentGroupsArgs = {'X-Gusto-API-Version'?: '2026-06-15' | undefined, company_id: string, body: {check_date: string, creation_token: string, submission_blockers?: (Array<{blocker_type?: string | undefined, selected_option?: (string | null) | undefined, message?: string | undefined, options?: (Array<{type?: string | undefined, message?: string | undefined}>) | undefined}>) | undefined, contractor_payments: Array<{contractor_uuid?: string | undefined, payment_method?: ('Direct Deposit' | 'Check' | 'Historical Payment') | undefined, wage?: unknown | undefined, hours?: unknown | undefined, bonus?: unknown | undefined, reimbursement?: unknown | undefined, invoice_number?: string | undefined, memo?: string | undefined}>}}; export type CreateApiV1CompaniesCompanyIdContractorPaymentGroupsOptions = {baseUrl?: string | undefined, CompanyAccessAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const payrollSubmissionBlockerType = z.object({blocker_type: z.string().optional(), blocker_name: z.string().optional(), unblock_options: z.array(z.object({unblock_type: z.string().optional(), check_date: z.string().optional(), metadata: z.record(z.string(), z.unknown()).optional()})).optional(), selected_option: z.string().nullable().optional(), status: z.enum(["unresolved", "resolved"]).optional()}); export const payrollCreditBlockerUnblockOptionSubmitWire = z.object({unblock_type: z.literal("submit_wire"), check_date: z.string(), metadata: z.object({wire_in_amount: z.string(), wire_in_deadline: z.string(), wire_in_request_uuid: z.string()})}); export const payrollCreditBlockerUnblockOptionSubmitBankScreenshot = z.object({unblock_type: z.literal("submit_bank_screenshot"), check_date: z.string(), metadata: z.object({information_request_uuid: z.string(), bank_account_last_four_digits: z.string().nullable().optional()})}); export const payrollCreditBlockerUnblockOptionRespondToHighRiskFraudRfi = z.object({unblock_type: z.literal("respond_to_high_risk_fraud_rfi"), check_date: z.string(), metadata: z.object({information_request_uuid: z.string()})}); export const payrollCreditBlockerUnblockOptionWaitForReverseWire = z.object({unblock_type: z.literal("wait_for_reverse_wire"), check_date: z.string(), metadata: z.object({})}); export const payrollCreditBlockerType = z.object({blocker_type: z.string().optional(), blocker_name: z.string().optional(), unblock_options: z.array(z.discriminatedUnion("unblock_type", [payrollCreditBlockerUnblockOptionSubmitWire, payrollCreditBlockerUnblockOptionSubmitBankScreenshot, payrollCreditBlockerUnblockOptionRespondToHighRiskFraudRfi, payrollCreditBlockerUnblockOptionWaitForReverseWire])).optional(), selected_option: z.string().nullable().optional(), status: z.enum(["unresolved", "pending_review", "resolved", "failed"]).optional()}); export const contractorPaymentForGroup = z.object({uuid: z.string().optional(), contractor_uuid: z.string().optional(), bonus: z.string().optional(), hours: z.string().optional(), payment_method: z.enum(["Direct Deposit", "Check", "Historical Payment", "Correction Payment"]).optional(), reimbursement: z.string().optional(), status: z.enum(["Funded", "Unfunded"]).optional(), hourly_rate: z.string().optional(), may_cancel: z.boolean().optional(), wage: z.string().optional(), wage_type: z.enum(["Hourly", "Fixed"]).optional(), wage_total: z.string().optional(), invoice_number: z.string().nullable().optional(), memo: z.string().nullable().optional()}); export const contractorPaymentGroup = z.object({uuid: z.string().optional(), company_uuid: z.string().optional(), check_date: z.string().optional(), debit_date: z.string().optional(), status: z.enum(["Unfunded", "Funded"]).optional(), creation_token: z.string().nullable().optional(), partner_owned_disbursement: z.boolean().nullable().optional(), submission_blockers: z.array(payrollSubmissionBlockerType).optional(), credit_blockers: z.array(payrollCreditBlockerType).optional(), totals: z.object({amount: z.string().optional(), debit_amount: z.string().optional(), wage_amount: z.string().optional(), reimbursement_amount: z.string().optional(), check_amount: z.string().optional()}).optional(), contractor_payments: z.array(contractorPaymentForGroup).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 }; /** * Create a contractor payment group * * POST /v1/companies/{company_id}/contractor_payment_groups */ export const createApiV1CompaniesCompanyIdContractorPaymentGroups = async (args: CreateApiV1CompaniesCompanyIdContractorPaymentGroupsArgs, options?: CreateApiV1CompaniesCompanyIdContractorPaymentGroupsOptions) => { 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))}/contractor_payment_groups${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(contractorPaymentGroup, await res.json()) };