import {z} from 'zod' export type AgenciesV2GetAgentsByLocationRequest = {suburbs?: (Array | null) | undefined, suburbIds?: (Array | null) | undefined, sortBy?: ('default' | 'nameAscending' | 'nameDescending' | 'totalSoldAscending' | 'totalSoldAndAuctionedAscending' | 'totalSoldAndAuctionedDescending' | 'totalSoldDescending' | 'avgSalePriceAscending' | 'avgSalePriceDescending' | 'avgDayOnMarketAscending' | 'avgDayOnMarketDescending' | 'forSaleAscending' | 'forSaleDescending' | 'forRentAscending' | 'forRentDescending' | 'totalLeasedDescending') | undefined, page?: (number | null) | undefined, pageSize?: (number | null) | undefined, agentNameKeyword?: (string | null) | undefined, agentType?: ('all' | 'sale' | 'rent' | 'soldOnly') | undefined, propertyType?: (string | null) | undefined, bedrooms?: (number | null) | undefined}; export type CreateApiV2AgentsearchAgentsLocationArgs = {body: AgenciesV2GetAgentsByLocationRequest}; export type CreateApiV2AgentsearchAgentsLocationOptions = {baseUrl?: string | undefined, apikey?: string | undefined, fetch?: typeof fetch | undefined}; export const agenciesV2ContactStatsDto = z.object({id: z.number().int().nullable().optional(), name: z.string().nullable().optional(), agentIdV2: z.string().nullable().optional(), propertyType: z.string().nullable().optional(), bedrooms: z.number().nullable().optional(), profileTier: z.string().nullable().optional(), depthTier: z.string().nullable().optional(), currentProductTier: z.string().nullable().optional(), profileUrl: z.string().nullable().optional(), profilePhoto: z.string().nullable().optional(), thumbnail: z.string().nullable().optional(), jobTitle: z.string().nullable().optional(), jobCategory: z.string().nullable().optional(), mobile: z.string().nullable().optional(), telephone: z.string().nullable().optional(), email: z.string().nullable().optional(), averageSoldDaysOnMarket: z.number().nullable().optional(), averageSoldPrice: z.number().nullable().optional(), averageSoldPriceIncWithheld: z.number().nullable().optional(), maxSoldPrice: z.number().nullable().optional(), maxSoldPriceIncWithheld: z.number().nullable().optional(), minSoldPrice: z.number().nullable().optional(), minSoldPriceIncWithheld: z.number().nullable().optional(), totalForRent: z.number().int().nullable().optional(), totalLeased: z.number().int().nullable().optional(), totalForSale: z.number().int().nullable().optional(), totalSold: z.number().int().nullable().optional(), totalJointSold: z.number().int().nullable().optional(), totalJointLeased: z.number().int().nullable().optional(), totalSoldAndAuctioned: z.number().int().nullable().optional(), totalJointSoldAndAuctioned: z.number().int().nullable().optional(), totalDaysOnMarket: z.number().nullable().optional(), totalSoldPrice: z.number().int().nullable().optional(), totalSoldPriceIncWithheld: z.number().int().nullable().optional(), totalAuctioned: z.number().int().nullable().optional(), totalNotWithheldSoldCount: z.number().int().nullable().optional(), totalSoldWithValidDaysOnMarket: z.number().int().nullable().optional(), agencyId: z.number().int().nullable().optional(), agencyName: z.string().nullable().optional(), agencyLogoSmall: z.string().nullable().optional(), agencyLogoUrl: z.string().nullable().optional(), brandColour: z.string().nullable().optional(), agencyProfileUrl: z.string().nullable().optional(), showRecentlySold: z.boolean().nullable().optional()}); export const agenciesV2AgentSearchPageResultContactStatsDto = z.object({total: z.number().int().nullable().optional(), totalPages: z.number().int().nullable().optional(), pageNumber: z.number().int().nullable().optional(), results: z.array(agenciesV2ContactStatsDto).nullable().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 }; /** * Retrieves agents matching the specified location criteria. * * POST /v2/agentsearch/agents/location * * Also accepts auth: oauth2 */ export const createApiV2AgentsearchAgentsLocation = async (args: CreateApiV2AgentsearchAgentsLocationArgs, options?: CreateApiV2AgentsearchAgentsLocationOptions) => { 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(/\/+$/, '')}/v2/agentsearch/agents/location${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(agenciesV2AgentSearchPageResultContactStatsDto, await res.json()) };