import {z} from 'zod' export type VoipUser = {id?: number | undefined, departmentId?: number | undefined, accountId?: number | undefined, displayName?: (string | null) | undefined, phone1?: (string | null) | undefined, phone2?: (string | null) | undefined, userName: string, password: string, extNumber: string, ownerUserId?: number | undefined, status?: number | undefined, recordOutgoingCall?: number | undefined, recordIncomingCall?: number | undefined, voiceMailStatus?: number | undefined, voiceMailPinStatus?: number | undefined, voiceMailPinCode?: (string | null) | undefined, codecList?: (string | null) | undefined, workingHourType?: number | undefined, userType?: number | undefined, virtualNumber?: (string | null) | undefined, createdUserId?: number | undefined, createdDate?: string | undefined, updatedUserId?: number | undefined, updatedDate?: string | undefined, redirectActionType?: number | undefined, redirectWavFile?: (string | null) | undefined, redirectActionParameter?: (string | null) | undefined, outOfOfficeActionType?: number | undefined, outOfOfficeWavFile?: (string | null) | undefined, outOfOfficeActionParameter?: (string | null) | undefined, notRegisterActionType?: number | undefined, notRegisterWavFile?: (string | null) | undefined, notRegisterActionParameter?: (string | null) | undefined, busyActionType?: number | undefined, busyWavFile?: (string | null) | undefined, busyActionParameter?: (string | null) | undefined, noAnswerActionType?: number | undefined, noAnswerWaitTime?: number | undefined, noAnswerWavFile?: (string | null) | undefined, noAnswerActionParameter?: (string | null) | undefined, holdLineEnabled?: number | undefined, transferCallEnabled?: number | undefined, popupStatus?: number | undefined, popupPage?: (string | null) | undefined, popupOutboundStatus?: number | undefined, sipServerId?: number | undefined, userState?: number | undefined, queueId?: number | undefined, callAvailability?: number | undefined, defaultCallExtension?: (string | null) | undefined, lastStateStartTime?: (string | null) | undefined}; export type CreateApiV1CallcenterVoipusersInsertbulkArgs = {body: Array}; export type CreateApiV1CallcenterVoipusersInsertbulkOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const insertBulkError = z.object({row: z.number().int().optional(), error: z.string().nullable().optional()}); export const insertBulkResponse = z.object({inserted: z.number().int().optional(), updated: z.number().int().optional(), errors: z.array(insertBulkError).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 }; /** * POST /v1/callcenter/voipusers/insertbulk * * Also accepts auth: API Key */ export const createApiV1CallcenterVoipusersInsertbulk = async (args: CreateApiV1CallcenterVoipusersInsertbulkArgs, options: CreateApiV1CallcenterVoipusersInsertbulkOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/callcenter/voipusers/insertbulk${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(insertBulkResponse, await res.json()) };