import { z } from "zod";
import { Genre } from "../metadata/genre";

export const SimilarTitle = z.object({
	title: z.string(),
	description: z.string().or(z.number()),
	poster: z.url().nullable().optional(),
});

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

export const CommonDetails = z.object({
	id: z.int().positive(),
	title: z.string().min(1, "Title is required").max(500, "Title too long"),
	originalTitle: z.string(),
	year: z.int().positive(),
	description: z.string(),
	genres: Genre.array(),
	rating: z
		.number()
		.min(0, "Rating must be at least 0")
		.max(10, "Rating must be at most 10")
		.multipleOf(0.1, "Rating precision must be 0.1")
		.nullable(),
	poster: z.url().nullable().optional(),
	backdrop: z.url().nullable().optional(),
	similarTitle: SimilarTitle.array().nullable().optional(),
});

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