import {z} from 'zod' export type GetApiPortalApiV1MovieSoonArgs = {includeMovieId?: Array | undefined, movieContext?: Array | undefined, partnerCode?: string | undefined, publishedDateIni?: string | undefined, publishedDateFin?: string | undefined, cityCode?: string | undefined, getUrl?: boolean | undefined, imgType?: string | undefined, videoType?: string | undefined}; export type GetApiPortalApiV1MovieSoonOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const movieSummary = z.object({id: z.number().int().optional(), name: z.string().optional(), url: z.string().optional(), imgUrl: z.string().optional(), videoUrl: z.string().optional(), releaseDate: z.string().optional()}); export const getApiPortalApiV1MovieSoonResponse = z.array(movieSummary); 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 que serĂ£o exibidos "Em Breve" * * GET /Portal/api/v1/movie/soon */ export const getApiPortalApiV1MovieSoon = async (args: GetApiPortalApiV1MovieSoonArgs, options?: GetApiPortalApiV1MovieSoonOptions) => { 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.includeMovieId ?? []) query.append("includeMovieId", String(item)) for (const item of args.movieContext ?? []) query.append("movieContext", String(item)) if (args.partnerCode != null) query.append("partnerCode", String(args.partnerCode)) if (args.publishedDateIni != null) query.append("publishedDateIni", String(args.publishedDateIni)) if (args.publishedDateFin != null) query.append("publishedDateFin", String(args.publishedDateFin)) if (args.cityCode != null) query.append("cityCode", String(args.cityCode)) if (args.getUrl != null) query.append("getUrl", String(args.getUrl)) if (args.imgType != null) query.append("imgType", String(args.imgType)) if (args.videoType != null) query.append("videoType", String(args.videoType)) const url = `${baseUrl.replace(/\/+$/, '')}/Portal/api/v1/movie/soon${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(getApiPortalApiV1MovieSoonResponse, await res.json()) };