import {z} from 'zod' export type LocationForSmartSearchOnBrandsShowRequest = {located_in_market?: string | undefined, market?: string | undefined, league?: string | undefined, brand?: string | undefined, city?: string | undefined, category?: string | undefined, subcategory?: string | undefined, state?: string | undefined, order_by?: ('brand' | 'category' | 'subcategory' | 'street' | 'city' | 'state' | 'country' | 'total_deals_count') | undefined, order_direction?: ('asc' | 'desc') | undefined, page?: number | undefined, per_page?: number | undefined}; export type CreateApiApiSearchSmartBrandsLocationsArgs = {body: LocationForSmartSearchOnBrandsShowRequest}; export type CreateApiApiSearchSmartBrandsLocationsOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const locationForSmartSearchOnBrandsShowResource = z.object({company_id: z.number().int().optional(), company_logo: z.string().optional(), company_name: z.string().optional(), subcategory_id: z.number().int().optional(), subcategory_name: z.string().optional(), category_id: z.number().int().optional(), category_name: z.string().optional(), street: z.string().optional(), is_hq: z.number().int().optional(), city_name: z.string().optional(), city_id: z.number().int().optional(), state_name: z.string().optional(), state_id: z.number().int().optional(), county_name: z.string().optional(), county_id: z.number().int().optional(), country_name: z.string().optional(), country_id: z.number().int().optional()}); export const createApiApiSearchSmartBrandsLocationsResponse = z.object({data: z.array(locationForSmartSearchOnBrandsShowResource).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 }; /** * Search brand locations * * POST /api/search/smart/brands/locations */ export const createApiApiSearchSmartBrandsLocations = async (args: CreateApiApiSearchSmartBrandsLocationsArgs, options: CreateApiApiSearchSmartBrandsLocationsOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/search/smart/brands/locations${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(createApiApiSearchSmartBrandsLocationsResponse, await res.json()) };