import {z} from 'zod' export type CreateApiApiBrandIdPropertiesYearArgs = {id: number, year: string, per_page?: number | undefined, page?: number | undefined, download?: boolean | undefined, with_brands?: boolean | undefined, property_type?: string | undefined, market?: string | undefined, item_type?: string | undefined, order_by?: ('property' | 'property_type' | 'market' | 'total_assets_count' | 'deal_revenues') | undefined, order_direction?: ('asc' | 'desc') | undefined}; export type CreateApiApiBrandIdPropertiesYearOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiBrandIdPropertiesYearResponse = z.object({}); 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 brand deals by season * * POST /api/brand/{id}/properties/{year} */ export const createApiApiBrandIdPropertiesYear = async (args: CreateApiApiBrandIdPropertiesYearArgs, options: CreateApiApiBrandIdPropertiesYearOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.page != null) query.append("page", String(args.page)) if (args.download != null) query.append("download", String(args.download)) if (args.with_brands != null) query.append("with_brands", String(args.with_brands)) if (args.property_type != null) query.append("property_type", String(args.property_type)) if (args.market != null) query.append("market", String(args.market)) if (args.item_type != null) query.append("item_type", String(args.item_type)) if (args.order_by != null) query.append("order_by", String(args.order_by)) if (args.order_direction != null) query.append("order_direction", String(args.order_direction)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/brand/${encodeURIComponent(String(args.id))}/properties/${encodeURIComponent(String(args.year))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiApiBrandIdPropertiesYearResponse, await res.json()) };