import { z } from "zod";
import { MetadataLanguage } from "../language";
import { ProviderId } from "./providers";

export const SeriesInfo = z.object({
	/** File Name */
	fileName: z.string(),
	/** Duration playback in seconds */
	runtimeSeconds: z.number(),
	/** Title Name*/
	title: z.string(),
	/** Title Year */
	year: z.number().nullable(),
	/** Language Data selection */
	language: z.string(),
	metadataLanguage: MetadataLanguage,
	season: z.number(),
	episode: z.number(),
});
export type SeriesInfo = z.infer<typeof SeriesInfo>;

export const ResolvedSeriesMetadata = z.object({
	id: z.string(),
	title: z.string(),
	originalTitle: z.string(),
	description: z.string(),
	tagline: z.string().optional(),
	year: z.number().optional(),
	status: z.string().optional(), // "RETURNING" | "ENDED" | ...
	genres: z.string().array(),
	posterUrl: z.string().nullable(),
	backdropUrl: z.string().nullable(),
	rating: z.number().optional(),
	popularity: z.number().optional(),
	language: z.string(),
	originalLanguage: z.string().optional(),
	countries: z.string().array(),
	homepage: z.string().optional(),
	firstAirDate: z.string().optional(), // Series first air date
	providerIds: ProviderId.array().optional(), // Array of external provider IDs
	// Season and episode objects
	season: z.object({
		number: z.number(),
		name: z.string().optional(),
	}),
	episode: z.object({
		number: z.number(),
		title: z.string().optional(),
		description: z.string().optional(),
		backgroundUrl: z.string().nullable().optional(),
	}),
	airDate: z.string().optional(), // Episode air date
	runtimeSeconds: z.number().optional(),
});
export type ResolvedSeriesMetadata = z.infer<typeof ResolvedSeriesMetadata>;
export type ResolvedSeriesMetadataResult = ResolvedSeriesMetadata | null;

// Credits
export const SeriesCreditsQuery = z.object({
	providerId: z.string(),
});
export type SeriesCreditsQuery = z.infer<typeof SeriesCreditsQuery>;

export const SeriesEpisodeCreditsQuery = z.object({
	seriesId: z.union([z.string(), z.number()]),
	seasonNumber: z.number(),
	episodeNumber: z.number(),
});

export type SeriesEpisodeCreditsQuery = z.infer<
	typeof SeriesEpisodeCreditsQuery
>;
