import {z} from 'zod' export type AssistantTransferRulesBulkRequest = {entries: Array<{assistants: Array, name: string, metadata?: ({city?: string | undefined, state?: string | undefined, zip?: string | undefined, address?: string | undefined, suiteBuildingRoom?: string | undefined, specialty?: string | undefined, action?: string | undefined}) | undefined, enabled?: boolean | undefined, type: 'intent_routing' | 'rule_based', assistantNumbers?: Array | undefined, transferNumber: string, transferMessage?: string | undefined, transferFailedMessage?: string | undefined, afterHoursEndCallMessage?: string | undefined, timezone?: string | undefined, textPatientBackInHub?: ({enabled?: boolean | undefined, minutesBeforeClosingTime?: number | undefined}) | undefined, textPatientBackConfirmationSentMessage?: string | undefined, hubSmsTextPatientBackConfirmationSentMessage?: string | undefined, offerToTransferMessage?: string | undefined, offerToTextBackOrTransferMessage?: string | undefined, offerToTextBackOrEndCallMessage?: string | undefined, officeClosedTransferNotAvailableOfferToTextBackMessage?: string | undefined, officeNearClosingTimeTransferNotAdvisedOfferToTextBackMessage?: string | undefined, workingHours?: Array<{earliest: {hour: number, minute: number}, latest: {hour: number, minute: number}, dayOfWeek: number}> | undefined}>, replaceAll?: boolean | undefined}; export type CreateApiAssistantTransferRulesBulkArgs = {body: AssistantTransferRulesBulkRequest}; export type CreateApiAssistantTransferRulesBulkOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const assistantTransferRulesResponse = z.object({_id: z.string().min(24).max(24).optional(), user: z.string().min(24).max(24).optional(), deleted: z.number().int().optional(), createdBy: z.string().min(24).max(24).optional(), updatedBy: z.string().min(24).max(24).optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), name: z.string().optional(), metadata: z.object({city: z.string().optional(), state: z.string().optional(), zip: z.string().optional(), address: z.string().optional(), suiteBuildingRoom: z.string().optional(), specialty: z.string().optional(), action: z.string().optional()}).optional(), enabled: z.boolean().optional(), type: z.enum(["intent_routing", "rule_based"]).optional(), assistants: z.array(z.string().min(24).max(24)).optional(), assistantNumbers: z.array(z.string().min(24).max(24)).optional(), transferNumber: z.string().optional(), transferMessage: z.string().optional(), transferFailedMessage: z.string().optional(), afterHoursEndCallMessage: z.string().optional(), timezone: z.string().optional(), textPatientBackInHub: z.object({enabled: z.boolean().optional(), minutesBeforeClosingTime: z.number().int().optional()}).optional(), textPatientBackConfirmationSentMessage: z.string().optional(), hubSmsTextPatientBackConfirmationSentMessage: z.string().optional(), offerToTransferMessage: z.string().optional(), offerToTextBackOrTransferMessage: z.string().optional(), offerToTextBackOrEndCallMessage: z.string().optional(), officeClosedTransferNotAvailableOfferToTextBackMessage: z.string().optional(), officeNearClosingTimeTransferNotAdvisedOfferToTextBackMessage: z.string().optional(), workingHours: z.array(z.object({earliest: z.object({hour: z.number().int().gte(0).lte(23).optional(), minute: z.number().int().gte(0).lte(59).optional()}).optional(), latest: z.object({hour: z.number().int().gte(0).lte(23).optional(), minute: z.number().int().gte(0).lte(59).optional()}).optional(), dayOfWeek: z.number().int().gte(0).lte(6).optional()})).optional()}); export const createApiAssistantTransferRulesBulkResponse = z.object({createdRules: z.array(assistantTransferRulesResponse).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 }; /** * Bulk create assistant transfer rules * * POST /assistantTransferRules/bulk */ export const createApiAssistantTransferRulesBulk = async (args: CreateApiAssistantTransferRulesBulkArgs, options?: CreateApiAssistantTransferRulesBulkOptions) => { const {baseUrl = "https://api.lumahealth.io/api/v2", 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(/\/+$/, '')}/assistantTransferRules/bulk${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(createApiAssistantTransferRulesBulkResponse, await res.json()) };