import {z} from 'zod' export type ApiRoutersCustomerCustomerDbCarBookingPayload = {app_user_id: number, car_owner_id: number, booking_start_date: string, booking_end_date: string, booking_hours: number, booking_price: number, original_booking_price?: number | undefined, booking_surge_amount: number, booking_advance_amount: number, booking_remaining_amount: number, car_wash_price: number, car_wash_type?: string | undefined, booking_total_amount: number, booking_amount_paid?: number | undefined, damage_protection_plan: string, damage_protection_amount: number, booking_from: string, razorpay_order_id: string, home_delivery_required?: string | undefined, home_delivery_charges: number, delivery_location: string, delivery_latitude: string, delivery_longitude: string, customer_location?: string | undefined, customer_latitude?: string | undefined, customer_longitude?: string | undefined, early_pickup_charges?: number | undefined, early_return_charges?: number | undefined, late_pickup_charges?: number | undefined, late_return_charges?: number | undefined, cash_back_used?: number | undefined, booking_amount_refunded?: number | undefined, amount_tobe_paid_for_ui?: number | undefined, discount_applied?: number | undefined, convenience_fee?: number | undefined, hike_percentile?: number | undefined, customer_current_latitude?: string | undefined, customer_current_longitude?: string | undefined, influencer_id?: number | undefined, force_to_double_booking?: string | undefined, is_free_booking?: string | undefined, driver_fee?: number | undefined, new_user_discount_applied?: number | undefined, addon_price?: number | undefined, halting_price?: number | undefined, is_one_rupee_booking?: string | undefined, subscription_points_used?: number | undefined, coupon_code?: string | undefined, coupon_amount?: number | undefined, zero_headache_plan?: string | undefined, zero_headache_amount?: number | undefined, limited_kilometers?: number | undefined, limited_plan?: number | undefined, is_spot_payment?: string | undefined, device_id?: string | undefined, hike_amount?: number | undefined, challan_amount?: number | undefined, car_not_available_discount?: number | undefined}; export type CreateApiLUserDcCarBookingArgs = {body: ApiRoutersCustomerCustomerDbCarBookingPayload}; export type CreateApiLUserDcCarBookingOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiLUserDcCarBookingResponse = z.unknown(); 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 }; /** * Book Car * * POST /l-user-dc/car-booking */ export const createApiLUserDcCarBooking = async (args: CreateApiLUserDcCarBookingArgs, options?: CreateApiLUserDcCarBookingOptions) => { const {baseUrl = "https://api.longdrivecars.com", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/l-user-dc/car-booking${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(createApiLUserDcCarBookingResponse, await res.json()) };