import { z } from "zod";

const LIBRARY_TYPES = ["MOVIE", "SERIES"] as const;

export const ListLibrariesOutputSchema = z.array(
	z.object({
		id: z.number(),
		name: z.string(),
		type: z.enum(LIBRARY_TYPES),
		path: z.string(),
		primaryLanguage: z.string(),
		fallbackLanguage: z.string(),
		createdAt: z.date(),
		updatedAt: z.date(),
	}),
);

export type ListLibrariesOutput = z.infer<typeof ListLibrariesOutputSchema>;

export const GetLibraryInputSchema = z.object({
	id: z.number(),
});

export type GetLibraryInput = z.infer<typeof GetLibraryInputSchema>;

export const GetLibraryOutputSchema = z.object({
	id: z.number(),
	name: z.string(),
	type: z.enum(LIBRARY_TYPES),
	path: z.string(),
	primaryLanguage: z.string(),
	fallbackLanguage: z.string(),
	createdAt: z.date(),
	updatedAt: z.date(),
});

export type GetLibraryOutput = z.infer<typeof GetLibraryOutputSchema>;

export const CreateLibraryInputSchema = z.object({
	name: z.string().min(1, "Library name is required"),
	type: z.enum(LIBRARY_TYPES),
	path: z.string().min(1, "Library path is required"),
	primaryLanguage: z.string().default("en"),
	fallbackLanguage: z.string().default("en"),
});

export type CreateLibraryInput = z.infer<typeof CreateLibraryInputSchema>;

export const CreateLibraryOutputSchema = z.object({
	id: z.number(),
	name: z.string(),
	type: z.enum(LIBRARY_TYPES),
	path: z.string(),
	primaryLanguage: z.string(),
	fallbackLanguage: z.string(),
	createdAt: z.date(),
	updatedAt: z.date(),
});

export type CreateLibraryOutput = z.infer<typeof CreateLibraryOutputSchema>;

export const UpdateLibraryInputSchema = z.object({
	id: z.number(),
	name: z.string().min(1).optional(),
	path: z.string().min(1).optional(),
	primaryLanguage: z.string().optional(),
	fallbackLanguage: z.string().optional(),
});

export type UpdateLibraryInput = z.infer<typeof UpdateLibraryInputSchema>;

export const UpdateLibraryOutputSchema = z.object({
	id: z.number(),
	name: z.string(),
	type: z.enum(LIBRARY_TYPES),
	path: z.string(),
	primaryLanguage: z.string(),
	fallbackLanguage: z.string(),
	createdAt: z.date(),
	updatedAt: z.date(),
});

export type UpdateLibraryOutput = z.infer<typeof UpdateLibraryOutputSchema>;

export const DeleteLibraryInputSchema = z.object({
	id: z.number(),
});

export type DeleteLibraryInput = z.infer<typeof DeleteLibraryInputSchema>;

export const DeleteLibraryOutputSchema = z.object({
	success: z.boolean(),
	message: z.string(),
});

export type DeleteLibraryOutput = z.infer<typeof DeleteLibraryOutputSchema>;

export const ScanLibraryInputSchema = z.object({
	id: z.number(),
});

export type ScanLibraryInput = z.infer<typeof ScanLibraryInputSchema>;

export const ScanLibraryOutputSchema = z.object({
	success: z.boolean(),
	message: z.string(),
});

export type ScanLibraryOutput = z.infer<typeof ScanLibraryOutputSchema>;
