import {z} from 'zod' export type BannerUpdate = {title?: (string | null) | undefined, placement?: (string | null) | undefined, location_id?: (number | null) | undefined, is_active?: (boolean | null) | undefined, sort_order?: (number | null) | undefined, duration_seconds?: (number | null) | undefined, show_limit?: (number | null) | undefined, show_period?: (string | null) | undefined, starts_at?: (string | null) | undefined, ends_at?: (string | null) | undefined, details?: (string | null) | undefined, feed_position?: (number | null) | undefined, link_type?: (string | null) | undefined, link_url?: (string | null) | undefined, category_ids?: (Array | null) | undefined}; export type PatchApiApiV1AdminBannersBannerIdArgs = {banner_id: number, body: BannerUpdate}; export type PatchApiApiV1AdminBannersBannerIdOptions = {baseUrl: string, OAuth2PasswordBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const categoryRef = z.object({id: z.number().int(), name: z.string()}); export const bannerRead = z.object({id: z.number().int(), title: z.string(), image_url: z.string(), placement: z.string(), location_id: z.number().int().nullable().optional(), is_active: z.boolean(), sort_order: z.number().int(), duration_seconds: z.number().int(), show_limit: z.number().int(), show_period: z.string(), starts_at: z.string().nullable().optional(), ends_at: z.string().nullable().optional(), details: z.string().nullable().optional(), feed_position: z.number().int().nullable().optional(), link_type: z.string(), link_url: z.string().nullable().optional(), categories: z.array(categoryRef).optional(), created_at: z.string()}); 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 }; /** * Update Banner * * PATCH /api/v1/admin/banners/{banner_id} */ export const patchApiApiV1AdminBannersBannerId = async (args: PatchApiApiV1AdminBannersBannerIdArgs, options: PatchApiApiV1AdminBannersBannerIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2PasswordBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2PasswordBearer !== undefined) headers.set('authorization', `Bearer ${OAuth2PasswordBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/admin/banners/${encodeURIComponent(String(args.banner_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(bannerRead, await res.json()) };