import {z} from 'zod' export type SocialBoostV1RateForNewSocialBoostRequestModel = {agencyId: number, agentFirstName: string, agentLastName: string, agentEmail: string, suburb: string, postcode: string, state: string, propertyType: 'Unknown' | 'AcreageSemiRural' | 'ApartmentUnitFlat' | 'Aquaculture' | 'BlockOfUnits' | 'Carspace' | 'DairyFarming' | 'DevelopmentSite' | 'Duplex' | 'Farm' | 'FishingForestry' | 'NewHomeDesigns' | 'House' | 'NewHouseLand' | 'IrrigationServices' | 'NewLand' | 'Livestock' | 'NewApartments' | 'Penthouse' | 'Retirement' | 'RetirementVillage' | 'Rural' | 'SemiDetached' | 'SpecialistFarm' | 'Studio' | 'Terrace' | 'Townhouse' | 'VacantLand' | 'Villa' | 'Cropping' | 'Viticulture' | 'MixedFarming' | 'Grazing' | 'Horticulture' | 'Equine' | 'Farmlet' | 'Orchard' | 'RuralLifestyle', isRural: boolean, listingType: 'Sale' | 'Rent' | 'None', price: number, channel: 'Residential' | 'Commercial' | 'Business', bookingStartDate?: (string | null) | undefined}; export type CreateApiV1ProductsRatefornewsocialboostArgs = {body: SocialBoostV1RateForNewSocialBoostRequestModel}; export type CreateApiV1ProductsRatefornewsocialboostOptions = {baseUrl?: string | undefined, apikey?: string | undefined, fetch?: typeof fetch | undefined}; export const socialBoostV1ContractInfo = z.object({id: z.number().int().nullable().optional(), bookingProductId: z.number().int().nullable().optional(), agencyId: z.number().int().nullable().optional(), startDate: z.string().nullable().optional(), endDate: z.string().nullable().optional(), finishedDate: z.string().nullable().optional(), attributes: z.string().nullable().optional(), agentId: z.string().nullable().optional(), isAgentContract: z.boolean().nullable().optional()}); export const socialBoostV1ListingRateInfo = z.object({productListingLevel: z.enum(["None", "PlatinumExtend", "Platinum", "Gold", "Silver", "Branded", "Tier1", "Tier2", "Tier3"]).nullable().optional(), productListingRule: z.enum(["None", "EarlyAccess", "SocialBoostAll", "SocialBoostCasual", "SocialBoostRuralAll", "SocialBoostRuralCasual", "SocialBoostAgent", "SocialBoostRuralAgent"]).nullable().optional(), bookingProductId: z.number().int().nullable().optional(), bookingProductRateId: z.number().int().nullable().optional(), bookingProductName: z.string().nullable().optional(), durationInDays: z.number().int().nullable().optional(), costExGst: z.number().nullable().optional(), costIncGst: z.number().nullable().optional(), zoneId: z.number().int().nullable().optional(), productAttributes: z.string().nullable().optional(), rateAttributes: z.string().nullable().optional(), bookingMethod: z.string().nullable().optional(), productForRural: z.boolean().nullable().optional()}); export const socialBoostV1RateForNewSocialBoost = z.object({reason: z.enum(["BasedOnContract", "NoContractFound", "NoRateFound", "PropertyTypeExcluded"]).nullable().optional(), contract: socialBoostV1ContractInfo.optional(), rate: socialBoostV1ListingRateInfo.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 }; /** * Get updated pricing information for a hypothetical listing * * POST /v1/products/ratefornewsocialboost * * Also accepts auth: oauth2 */ export const createApiV1ProductsRatefornewsocialboost = async (args: CreateApiV1ProductsRatefornewsocialboostArgs, options?: CreateApiV1ProductsRatefornewsocialboostOptions) => { const {baseUrl = "https://api.domain.com.au", fetch: fetchFn = fetch, apikey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apikey !== undefined) headers.set("x-api-key", apikey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/products/ratefornewsocialboost${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(socialBoostV1RateForNewSocialBoost, await res.json()) };