import { z } from "zod";

import { AmqAnimeCategory, AmqAnimeGenre, AmqAnimeTag } from "./anime-extended";

export const Season = z.enum({
	Winter: 0,
	Spring: 1,
	Summer: 2,
	Fall: 3,
} as const);

export const SongLinkType = z.enum({
	OP: 1,
	ED: 2,
	INS: 3,
} as const);

const BooleanInt = z.enum({
	false: 0,
	true: 1,
} as const);

export const AmqSongLink = z.object({
	songId: z.int().positive(),
	number: z.int().nonnegative(),
	type: SongLinkType,
	annSongId: z.int().positive(),
	uploaded: BooleanInt,
	rebroadcast: BooleanInt,
	dub: BooleanInt,
});

export const AmqAnimeSchema = z.object({
	annId: z.int().positive(),
	aniListId: z.int().positive().nullable(),
	malId: z.int().positive(),
	kitsuId: z.int().positive().nullable(),
	category: z.object({
		name: AmqAnimeCategory,
		number: z.union([z.number(), z.string()]).nullable(),
	}),
	genres: z.array(AmqAnimeGenre),
	tags: z.array(AmqAnimeTag),
	mainName: z.string(),
	mainNames: z.object({
		EN: z.string().nullable(),
		JA: z.string().nullable(),
	}),
	names: z.array(
		z.object({
			language: z.enum(["EN", "JA"]),
			name: z.string(),
		}),
	),
	year: z.int().positive(),
	seasonId: Season,
	songLinks: z.array(AmqSongLink),
	opCount: z.int().nonnegative(),
	edCount: z.int().nonnegative(),
	insertCount: z.int().nonnegative(),
});
