import {z} from 'zod' export type AddImage = {attachment?: string | undefined, image_data?: string | undefined}; export type RestaurantMenuPriceUpdate = {restaurant_menu_id?: number | undefined, price_type_id?: number | undefined, price_type_name?: string | undefined, price?: number | undefined}; export type RestaurantMenuAddonPriceUpdate = {restaurant_menu_id: number, restaurant_addon_item_id: number, restaurant_addon_id: number, price: number, is_active: number, is_free: number}; export type RestaurantAddonItemUpdate = {restaurant_addon_id: number, name: string, is_active: number, restaurant_menu_addon_price?: Array | undefined}; export type RestaurantAddonUpdate = {restaurant_id: number, restaurant_category_id: number, name: string, is_active: number, restaurant_addon_item?: Array | undefined}; export type RestaurantMenuUpdate = {restaurant_id?: number | undefined, cuisine_id?: number | undefined, restaurant_category_id?: number | undefined, menu_type_id?: number | undefined, name?: string | undefined, description?: string | undefined, is_addon?: number | undefined, is_popular?: number | undefined, is_spicy?: number | undefined, is_active?: number | undefined, image?: AddImage | undefined, restaurant_menu_price?: Array | undefined, restaurant_addon?: Array | undefined}; export type UpdateApiRestaurantMenusRestaurantMenuIdArgs = {restaurantMenuId: number, body: RestaurantMenuUpdate}; export type UpdateApiRestaurantMenusRestaurantMenuIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const addImage = z.object({attachment: z.string().optional(), image_data: z.string().optional()}); export const restaurantMenuPriceUpdate = z.object({restaurant_menu_id: z.number().int().optional(), price_type_id: z.number().int().optional(), price_type_name: z.string().optional(), price: z.number().optional()}); export const restaurantMenuAddonPriceUpdate = z.object({restaurant_menu_id: z.number().int(), restaurant_addon_item_id: z.number().int(), restaurant_addon_id: z.number().int(), price: z.number(), is_active: z.number().int(), is_free: z.number().int()}); export const restaurantAddonItemUpdate = z.object({restaurant_addon_id: z.number().int(), name: z.string(), is_active: z.number().int(), restaurant_menu_addon_price: z.array(restaurantMenuAddonPriceUpdate).optional()}); export const restaurantAddonUpdate = z.object({restaurant_id: z.number().int(), restaurant_category_id: z.number().int(), name: z.string(), is_active: z.number().int(), restaurant_addon_item: z.array(restaurantAddonItemUpdate).optional()}); export const restaurantMenuUpdate = z.object({restaurant_id: z.number().int().optional(), cuisine_id: z.number().int().optional(), restaurant_category_id: z.number().int().optional(), menu_type_id: z.number().int().optional(), name: z.string().optional(), description: z.string().optional(), is_addon: z.number().int().optional(), is_popular: z.number().int().optional(), is_spicy: z.number().int().optional(), is_active: z.number().int().optional(), image: addImage.optional(), restaurant_menu_price: z.array(restaurantMenuPriceUpdate).optional(), restaurant_addon: z.array(restaurantAddonUpdate).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 restaurant menu by its id * * PUT /restaurant_menus/{restaurantMenuId} */ export const updateApiRestaurantMenusRestaurantMenuId = async (args: UpdateApiRestaurantMenusRestaurantMenuIdArgs, options: UpdateApiRestaurantMenusRestaurantMenuIdOptions) => { 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(/\/+$/, '')}/restaurant_menus/${encodeURIComponent(String(args.restaurantMenuId))}${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(restaurantMenuUpdate, await res.json()) };