import {z} from 'zod' export type BidMatch = {bid_id?: Bid | undefined, booking_id?: number | undefined, conversation_id?: number | undefined, created?: string | undefined, id?: number | undefined, match_location_type?: (string | null) | undefined, message_sent?: boolean | undefined, owner_id?: number | undefined, owner_read?: boolean | undefined, rental_id?: number | undefined, renter_id?: number | undefined, score?: (number | null) | undefined, status?: string | undefined, updated?: string | undefined}; export type BidMatches = Array; export type NullFloat64 = {Float64?: number | undefined, Valid?: boolean | undefined}; export type Bid = {bid_matches?: BidMatches | undefined, close_reason?: string | undefined, closed?: string | undefined, closed_by_booking_id?: number | undefined, comments?: string | undefined, created?: string | undefined, created_by_booking_id?: (number | null) | undefined, delivery?: (boolean | null) | undefined, dest_lat?: number | undefined, dest_lng?: number | undefined, destination?: string | undefined, email?: string | undefined, festival_friendly?: boolean | undefined, from?: string | undefined, id?: number | undefined, ip_lookup?: boolean | undefined, make?: string | undefined, max_budget?: number | undefined, max_day_price?: number | undefined, message_sent?: boolean | undefined, min_budget?: number | undefined, min_day_price?: number | undefined, model?: string | undefined, name?: string | undefined, offer_delivery?: boolean | undefined, open?: boolean | undefined, owner_id?: number | undefined, owner_read?: boolean | undefined, pet_friendly?: boolean | undefined, pickup_lat?: number | undefined, pickup_lng?: number | undefined, pickup_location?: string | undefined, price_per_day?: number | undefined, quality?: NullFloat64 | undefined, rental_id?: number | undefined, seatbelts?: number | undefined, sent?: boolean | undefined, smoking_allowed?: boolean | undefined, source?: string | undefined, stationary_delivery?: (boolean | null) | undefined, tailgate_friendly?: boolean | undefined, to?: string | undefined, travelers?: number | undefined, type?: string | undefined, updated?: string | undefined, year?: number | undefined}; export type PatchApiBidsIdArgs = {id: number, body: Bid}; export type PatchApiBidsIdOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const bidMatch = z.object({bid_id: z.lazy(() => bid.optional()), booking_id: z.number().int().optional(), conversation_id: z.number().int().optional(), created: z.string().optional(), id: z.number().int().optional(), match_location_type: z.string().nullable().optional(), message_sent: z.boolean().optional(), owner_id: z.number().int().optional(), owner_read: z.boolean().optional(), rental_id: z.number().int().optional(), renter_id: z.number().int().optional(), score: z.number().int().nullable().optional(), status: z.string().optional(), updated: z.string().optional()}); export const bidMatches = z.array(bidMatch); export const nullFloat64 = z.object({Float64: z.number().optional(), Valid: z.boolean().optional()}); export const bid: z.ZodType = z.object({bid_matches: bidMatches.optional(), close_reason: z.string().optional(), closed: z.string().optional(), closed_by_booking_id: z.number().int().optional(), comments: z.string().optional(), created: z.string().optional(), created_by_booking_id: z.number().int().nullable().optional(), delivery: z.boolean().nullable().optional(), dest_lat: z.number().optional(), dest_lng: z.number().optional(), destination: z.string().optional(), email: z.string().optional(), festival_friendly: z.boolean().optional(), from: z.string().optional(), id: z.number().int().optional(), ip_lookup: z.boolean().optional(), make: z.string().optional(), max_budget: z.number().int().optional(), max_day_price: z.number().int().optional(), message_sent: z.boolean().optional(), min_budget: z.number().int().optional(), min_day_price: z.number().int().optional(), model: z.string().optional(), name: z.string().optional(), offer_delivery: z.boolean().optional(), open: z.boolean().optional(), owner_id: z.number().int().optional(), owner_read: z.boolean().optional(), pet_friendly: z.boolean().optional(), pickup_lat: z.number().optional(), pickup_lng: z.number().optional(), pickup_location: z.string().optional(), price_per_day: z.number().int().optional(), quality: nullFloat64.optional(), rental_id: z.number().int().optional(), seatbelts: z.number().int().optional(), sent: z.boolean().optional(), smoking_allowed: z.boolean().optional(), source: z.string().optional(), stationary_delivery: z.boolean().nullable().optional(), tailgate_friendly: z.boolean().optional(), to: z.string().optional(), travelers: z.number().int().optional(), type: z.string().optional(), updated: z.string().optional(), year: z.number().int().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 instamatch bid * * PATCH /bids/{id} * * Also accepts auth: API-Key */ export const patchApiBidsId = async (args: PatchApiBidsIdArgs, options: PatchApiBidsIdOptions) => { const {baseUrl, 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) const url = `${baseUrl.replace(/\/+$/, '')}/bids/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(bid, await res.json()) };