import {z} from 'zod' export type GetApiLiveTvSeriesTimersTimerIdArgs = {timerId: string}; export type GetApiLiveTvSeriesTimersTimerIdOptions = {baseUrl?: string | undefined, CustomAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const keepUntil = z.enum(["UntilDeleted", "UntilSpaceNeeded", "UntilWatched", "UntilDate"]); export const dayOfWeek = z.enum(["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]); export const dayPattern = z.enum(["Daily", "Weekdays", "Weekends"]); export const seriesTimerInfoDto = z.object({Id: z.string().nullable().optional(), Type: z.string().nullable().optional(), ServerId: z.string().nullable().optional(), ExternalId: z.string().nullable().optional(), ChannelId: z.string().optional(), ExternalChannelId: z.string().nullable().optional(), ChannelName: z.string().nullable().optional(), ChannelPrimaryImageTag: z.string().nullable().optional(), ProgramId: z.string().nullable().optional(), ExternalProgramId: z.string().nullable().optional(), Name: z.string().nullable().optional(), Overview: z.string().nullable().optional(), StartDate: z.string().optional(), EndDate: z.string().optional(), ServiceName: z.string().nullable().optional(), Priority: z.number().int().optional(), PrePaddingSeconds: z.number().int().optional(), PostPaddingSeconds: z.number().int().optional(), IsPrePaddingRequired: z.boolean().optional(), ParentBackdropItemId: z.string().nullable().optional(), ParentBackdropImageTags: z.array(z.string()).nullable().optional(), IsPostPaddingRequired: z.boolean().optional(), KeepUntil: keepUntil.optional(), RecordAnyTime: z.boolean().optional(), SkipEpisodesInLibrary: z.boolean().optional(), RecordAnyChannel: z.boolean().optional(), KeepUpTo: z.number().int().optional(), RecordNewOnly: z.boolean().optional(), Days: z.array(dayOfWeek).nullable().optional(), DayPattern: dayPattern.optional(), ImageTags: z.record(z.string(), z.string()).nullable().optional(), ParentThumbItemId: z.string().nullable().optional(), ParentThumbImageTag: z.string().nullable().optional(), ParentPrimaryImageItemId: z.string().nullable().optional(), ParentPrimaryImageTag: z.string().nullable().optional()}); 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 }; /** * Gets a live tv series timer. * * GET /LiveTv/SeriesTimers/{timerId} */ export const getApiLiveTvSeriesTimersTimerId = async (args: GetApiLiveTvSeriesTimersTimerIdArgs, options?: GetApiLiveTvSeriesTimersTimerIdOptions) => { const {baseUrl = "http://localhost", fetch: fetchFn = fetch, CustomAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (CustomAuthentication !== undefined) headers.set("X-Emby-Authorization", CustomAuthentication) const url = `${baseUrl.replace(/\/+$/, '')}/LiveTv/SeriesTimers/${encodeURIComponent(String(args.timerId))}${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(seriesTimerInfoDto, await res.json()) };