import {z} from 'zod' export type GetApiPortalApiV1MovieAllArgs = {movieContext?: Array | undefined, publishedDateIni?: string | undefined, publishedDateFin?: string | undefined, partnerCode?: string | undefined, getImgs?: boolean | undefined, getVideos?: boolean | undefined}; export type GetApiPortalApiV1MovieAllOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const homeSimpleEventViewModel = z.object({id: z.number().int().optional(), name: z.string().optional(), trailerURL: z.string().optional(), posterImage: z.string().optional()}); export const getApiPortalApiV1MovieAllResponse = z.array(homeSimpleEventViewModel); 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 }; /** * Lista os filmes cadastrados até um ano atrás conforme o filtro * * GET /Portal/api/v1/movie/all */ export const getApiPortalApiV1MovieAll = async (args: GetApiPortalApiV1MovieAllArgs, options?: GetApiPortalApiV1MovieAllOptions) => { const {baseUrl = "https://api.veloxtickets.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.movieContext ?? []) query.append("movieContext", String(item)) if (args.publishedDateIni != null) query.append("publishedDateIni", String(args.publishedDateIni)) if (args.publishedDateFin != null) query.append("publishedDateFin", String(args.publishedDateFin)) if (args.partnerCode != null) query.append("partnerCode", String(args.partnerCode)) if (args.getImgs != null) query.append("getImgs", String(args.getImgs)) if (args.getVideos != null) query.append("getVideos", String(args.getVideos)) const url = `${baseUrl.replace(/\/+$/, '')}/Portal/api/v1/movie/all${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiPortalApiV1MovieAllResponse, await res.json()) };