import {z} from 'zod' export type HolidaySchema = {createdAt?: (number | null) | undefined, updatedBy?: (string | null) | undefined, isArchived?: (boolean | null) | undefined, holidayDate: number | null, createdBy?: (string | null) | undefined, holidayName?: (string | null) | undefined, archivedAt?: (number | null) | undefined, updatedAt?: (number | null) | undefined, holidayType: 'public_holiday' | 'optional_holiday' | null, region?: (string | null) | undefined, holidayId?: (number | null) | undefined}; export type PatchApiApiV2ResourceManagementHolidaysHolidayIdArgs = {Authorization: string, holidayId: string, body: HolidaySchema}; export type PatchApiApiV2ResourceManagementHolidaysHolidayIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const holidaySchema = z.object({createdAt: z.number().int().nullable().optional(), updatedBy: z.string().nullable().optional(), isArchived: z.boolean().nullable().optional(), holidayDate: z.number().int().nullable(), createdBy: z.string().nullable().optional(), holidayName: z.string().nullable().optional(), archivedAt: z.number().int().nullable().optional(), updatedAt: z.number().int().nullable().optional(), holidayType: z.enum(["public_holiday", "optional_holiday"]).nullable(), region: z.string().nullable().optional(), holidayId: z.number().int().nullable().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 }; /** * Patch Holiday * * PATCH /api/v2/resource_management/holidays/{holidayId} */ export const patchApiApiV2ResourceManagementHolidaysHolidayId = async (args: PatchApiApiV2ResourceManagementHolidaysHolidayIdArgs, options?: PatchApiApiV2ResourceManagementHolidaysHolidayIdOptions) => { const {baseUrl = "https://apiv2.eightfold.ai", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/resource_management/holidays/${encodeURIComponent(String(args.holidayId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(holidaySchema, await res.json()) };