import {z} from 'zod' export type GetApiPortalApiV1MovieScheduledPartnerCodeCityCodePlaceIdArgs = {partnerCode: string, cityCode: string, placeId: string, eventMomentIni?: string | undefined, eventMomentFin?: string | undefined, getUrl?: boolean | undefined, imgType?: string | undefined, videoType?: string | undefined}; export type GetApiPortalApiV1MovieScheduledPartnerCodeCityCodePlaceIdOptions = {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 getApiPortalApiV1MovieScheduledPartnerCodeCityCodePlaceIdResponse = 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 com programação ativa conforme filtro * * GET /Portal/api/v1/movie/scheduled/{partnerCode}/{cityCode}/{placeId} */ export const getApiPortalApiV1MovieScheduledPartnerCodeCityCodePlaceId = async (args: GetApiPortalApiV1MovieScheduledPartnerCodeCityCodePlaceIdArgs, options?: GetApiPortalApiV1MovieScheduledPartnerCodeCityCodePlaceIdOptions) => { const {baseUrl = "https://api.veloxtickets.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.eventMomentIni != null) query.append("eventMomentIni", String(args.eventMomentIni)) if (args.eventMomentFin != null) query.append("eventMomentFin", String(args.eventMomentFin)) 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/scheduled/${encodeURIComponent(String(args.partnerCode))}/${encodeURIComponent(String(args.cityCode))}/${encodeURIComponent(String(args.placeId))}${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(getApiPortalApiV1MovieScheduledPartnerCodeCityCodePlaceIdResponse, await res.json()) };