import {z} from 'zod' export type RestaurantMenuPrice = {restaurant_menu_id?: number | undefined, price_type_id?: number | undefined, price_type_name?: string | undefined, price?: number | undefined}; export type AddImage = {attachment?: string | undefined, image_data?: string | undefined}; export type AddRestaurantMenu = {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, restaurant_menu_price?: RestaurantMenuPrice | undefined, image?: AddImage | undefined, color?: string | undefined, stock?: string | undefined}; export type CreateApiRestaurantMenusArgs = {body: AddRestaurantMenu}; export type CreateApiRestaurantMenusOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const restaurantMenuPrice = 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 addImage = z.object({attachment: z.string().optional(), image_data: z.string().optional()}); export const addRestaurantMenu = 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(), restaurant_menu_price: restaurantMenuPrice.optional(), image: addImage.optional(), color: z.string().optional(), stock: z.string().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 }; /** * Creates a new restaurant menu * * POST /restaurant_menus */ export const createApiRestaurantMenus = async (args: CreateApiRestaurantMenusArgs, options: CreateApiRestaurantMenusOptions) => { 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${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(addRestaurantMenu, await res.json()) };