import {z} from 'zod' export type ServiceVisibilityType = 'ALL' | 'NEW' | 'EXISTING' | 'NO'; export type Unit = 'AMPOULES' | 'APPLICATORS' | 'BOTTLES' | 'BOXES' | 'CAPSULES' | 'CUPS' | 'DOSES' | 'G_PER_ML' | 'GRAMS' | 'IU' | 'IU_PER_ML' | 'OUNCES' | 'FLUID_OUNCES' | 'KG' | 'KITS' | 'LITERS' | 'MCG' | 'MG' | 'MG_PER_ML' | 'ML' | 'MMOL' | 'MICROGRAM_PER_ML' | 'PACKS' | 'PAIRS' | 'PATCHES' | 'PERCENTAGE' | 'PIECES' | 'POUCHES' | 'ROLLS' | 'SACHETS' | 'SHEETS' | 'SPRAYS' | 'STRIPS' | 'SYRINGES' | 'TABLETS' | 'TABLETS_PER_DAY' | 'TESTS' | 'TUBES' | 'UNITS' | 'VIALS' | 'TREATMENTS' | 'SESSIONS' | 'PULSES' | 'JOULES' | 'CENTIMETERS' | 'THREAD_COUNT' | 'INJECTIONS' | 'WRINKLE_UNITS' | 'POUNDS' | 'FEET' | 'INCHES'; export type ServiceEdit = {id: string, name?: (string | null) | undefined, duration?: (number | null) | undefined, description?: (string | null) | undefined, price?: (number | null) | undefined, displayPrice?: (number | null) | undefined, costOfService?: number | undefined, estimated?: (boolean | null) | undefined, bookingFee?: (number | null) | undefined, bookingFeeText?: (string | null) | undefined, reminderDaysBefore?: (number | null) | undefined, cancellationCost?: (number | null) | undefined, hoursBeforeCancellingCosts?: (number | null) | undefined, bookingFeePercentage?: (number | null) | undefined, cancellationFeePctWithin24h?: (number | null) | undefined, cancellationFeePctWithin48h?: (number | null) | undefined, refundBookingFeeBefore48h?: (boolean | null) | undefined, hoursBeforeBookingFeeRefundable?: (number | null) | undefined, followUpDaysAfter?: (number | null) | undefined, followUpSmsTemplate?: (string | null) | undefined, reminderSmsTemplate?: (string | null) | undefined, locationIds?: (Array | null) | undefined, providerIds?: (Array | null) | undefined, createdDate?: (string | null) | undefined, updatedDate?: (string | null) | undefined, formIds?: (Array | null) | undefined, confirmationSmsTemplate?: (string | null) | undefined, cancellationSmsTemplate?: (string | null) | undefined, noShowSmsTemplate?: (string | null) | undefined, overrideNoticeSmsTemplate?: (string | null) | undefined, selfSchedulingBufferTime?: (number | null) | undefined, visibility?: (ServiceVisibilityType | null) | undefined, minutesBeforeRebookingAllowed?: (number | null) | undefined, color?: (string | null) | undefined, allowIndividualProviderBooking?: (boolean | null) | undefined, displayOrder?: (number | null) | undefined, reservedTimeMinutes?: (number | null) | undefined, category?: (string | null) | undefined, isDoubleBookable?: (boolean | null) | undefined, isPopular?: (boolean | null) | undefined, creditCardRequired?: (boolean | null) | undefined, collectCreditCard?: (boolean | null) | undefined, autoGfeTreatments?: (Array | null) | undefined, brandName?: (string | null) | undefined, unit?: (Unit | null) | undefined, internalNotes?: (string | null) | undefined, sortOrder?: (number | null) | undefined, taxable?: (boolean | null) | undefined, allowCustomPricing?: (boolean | null) | undefined}; export type CreateApiAdminServicesUpdateOrCreateArgs = {TENANT: string, 'API-KEY': string, body: ServiceEdit}; export type CreateApiAdminServicesUpdateOrCreateOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const serviceVisibilityType = z.enum(["ALL", "NEW", "EXISTING", "NO"]); export const unit = z.enum(["AMPOULES", "APPLICATORS", "BOTTLES", "BOXES", "CAPSULES", "CUPS", "DOSES", "G_PER_ML", "GRAMS", "IU", "IU_PER_ML", "OUNCES", "FLUID_OUNCES", "KG", "KITS", "LITERS", "MCG", "MG", "MG_PER_ML", "ML", "MMOL", "MICROGRAM_PER_ML", "PACKS", "PAIRS", "PATCHES", "PERCENTAGE", "PIECES", "POUCHES", "ROLLS", "SACHETS", "SHEETS", "SPRAYS", "STRIPS", "SYRINGES", "TABLETS", "TABLETS_PER_DAY", "TESTS", "TUBES", "UNITS", "VIALS", "TREATMENTS", "SESSIONS", "PULSES", "JOULES", "CENTIMETERS", "THREAD_COUNT", "INJECTIONS", "WRINKLE_UNITS", "POUNDS", "FEET", "INCHES"]); export const serviceEdit = z.object({id: z.string(), name: z.string().nullable().optional(), duration: z.number().int().nullable().optional(), description: z.string().nullable().optional(), price: z.number().int().nullable().optional(), displayPrice: z.number().int().nullable().optional(), costOfService: z.number().int().optional(), estimated: z.boolean().nullable().optional(), bookingFee: z.number().int().nullable().optional(), bookingFeeText: z.string().nullable().optional(), reminderDaysBefore: z.number().int().nullable().optional(), cancellationCost: z.number().int().nullable().optional(), hoursBeforeCancellingCosts: z.number().int().nullable().optional(), bookingFeePercentage: z.number().int().nullable().optional(), cancellationFeePctWithin24h: z.number().int().nullable().optional(), cancellationFeePctWithin48h: z.number().int().nullable().optional(), refundBookingFeeBefore48h: z.boolean().nullable().optional(), hoursBeforeBookingFeeRefundable: z.number().int().nullable().optional(), followUpDaysAfter: z.number().int().nullable().optional(), followUpSmsTemplate: z.string().nullable().optional(), reminderSmsTemplate: z.string().nullable().optional(), locationIds: z.array(z.string()).nullable().optional(), providerIds: z.array(z.string()).nullable().optional(), createdDate: z.string().nullable().optional(), updatedDate: z.string().nullable().optional(), formIds: z.array(z.string()).nullable().optional(), confirmationSmsTemplate: z.string().nullable().optional(), cancellationSmsTemplate: z.string().nullable().optional(), noShowSmsTemplate: z.string().nullable().optional(), overrideNoticeSmsTemplate: z.string().nullable().optional(), selfSchedulingBufferTime: z.number().int().nullable().optional(), visibility: serviceVisibilityType.nullable().optional(), minutesBeforeRebookingAllowed: z.number().int().nullable().optional(), color: z.string().nullable().optional(), allowIndividualProviderBooking: z.boolean().nullable().optional(), displayOrder: z.number().int().nullable().optional(), reservedTimeMinutes: z.number().int().nullable().optional(), category: z.string().nullable().optional(), isDoubleBookable: z.boolean().nullable().optional(), isPopular: z.boolean().nullable().optional(), creditCardRequired: z.boolean().nullable().optional(), collectCreditCard: z.boolean().nullable().optional(), autoGfeTreatments: z.array(z.string()).nullable().optional(), brandName: z.string().nullable().optional(), unit: unit.nullable().optional(), internalNotes: z.string().nullable().optional(), sortOrder: z.number().int().nullable().optional(), taxable: z.boolean().nullable().optional(), allowCustomPricing: z.boolean().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 }; /** * Update Or Create Service * * POST /admin/services/update-or-create */ export const createApiAdminServicesUpdateOrCreate = async (args: CreateApiAdminServicesUpdateOrCreateArgs, options: CreateApiAdminServicesUpdateOrCreateOptions) => { const {baseUrl, 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.TENANT != null) headers.set("TENANT", String(args.TENANT)) if (args['API-KEY'] != null) headers.set("API-KEY", String(args['API-KEY'])) const url = `${baseUrl.replace(/\/+$/, '')}/admin/services/update-or-create${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(serviceEdit, await res.json()) };