import {z} from 'zod' export type MenuItemCategory = 'FOOD' | 'COCKTAIL' | 'NON_ALCOHOLIC_COCKTAIL' | 'SIGNATURE' | 'LONG_DRINK' | 'WINE' | 'BEER' | 'SPIRIT' | 'COFFEE_TEA' | 'SMOOTHIE_SHAKE' | 'REFRESHMENT'; export type MenuItemWrite = {name: string, category?: MenuItemCategory | undefined, subcategory?: (string | null) | undefined, ingredients_text?: (string | null) | undefined, allergen_codes?: Array | undefined, tags?: Array | undefined, description?: (string | null) | undefined, image_url?: (string | null) | undefined, price?: (number | string | null) | undefined, currency?: (string | null) | undefined}; export type UpdateApiApiV1MenusPropertiesPropertyIdMenuItemsItemIdArgs = {property_id: string, item_id: string, body: MenuItemWrite}; export type UpdateApiApiV1MenusPropertiesPropertyIdMenuItemsItemIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const menuItemCategory = z.enum(["FOOD", "COCKTAIL", "NON_ALCOHOLIC_COCKTAIL", "SIGNATURE", "LONG_DRINK", "WINE", "BEER", "SPIRIT", "COFFEE_TEA", "SMOOTHIE_SHAKE", "REFRESHMENT"]); export const menuItemRead = z.object({id: z.string(), property_id: z.string(), name: z.string(), category: menuItemCategory, subcategory: z.string().nullable(), ingredients_text: z.string().nullable(), allergen_codes: z.array(z.string()), tags: z.array(z.string()), description: z.string().nullable(), image_url: z.string().nullable(), price: z.string().nullable(), currency: z.string().nullable()}); 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 Menu Item * * PUT /api/v1/menus/properties/{property_id}/menu-items/{item_id} */ export const updateApiApiV1MenusPropertiesPropertyIdMenuItemsItemId = async (args: UpdateApiApiV1MenusPropertiesPropertyIdMenuItemsItemIdArgs, options: UpdateApiApiV1MenusPropertiesPropertyIdMenuItemsItemIdOptions) => { 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") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/menus/properties/${encodeURIComponent(String(args.property_id))}/menu-items/${encodeURIComponent(String(args.item_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(menuItemRead, await res.json()) };