import { t } from "elysia";
import { comment } from "../../utils";

export const ExternalId = () =>
	t.Record(
		t.String(),
		t.Array(
			t.Object({
				dataId: t.String(),
				link: t.Nullable(t.String({ format: "url" })),
				label: t.Optional(t.Nullable(t.String())),
			}),
		),
	);

export const EpisodeId = t.Record(
	t.String(),
	t.Array(
		t.Object({
			serieId: t.String({
				descrpition: comment`
				Id on the external website.
				We store the serie's id because episode id are rarely stable.
			`,
			}),
			season: t.Nullable(
				t.Integer({
					description: "Null if the external website uses absolute numbering.",
				}),
			),
			episode: t.Integer(),
			link: t.Nullable(t.String({ format: "url" })),
			label: t.Optional(t.Nullable(t.String())),
		}),
	),
);
export type EpisodeId = typeof EpisodeId.static;

export const MovieEpisodeId = t.Record(
	t.String(),
	t.Array(
		t.Union([
			t.Object({
				dataId: t.String(),
				link: t.Nullable(t.String({ format: "url" })),
				label: t.Optional(t.Nullable(t.String())),
			}),
			t.Object({
				serieId: t.String({
					descrpition: comment`
				Id on the external website.
				We store the serie's id because episode id are rarely stable.
			`,
				}),
				season: t.Nullable(
					t.Integer({
						description:
							"Null if the external website uses absolute numbering.",
					}),
				),
				episode: t.Integer(),
				link: t.Nullable(t.String({ format: "url" })),
				label: t.Optional(t.Nullable(t.String())),
			}),
		]),
	),
);

export const SeasonId = t.Record(
	t.String(),
	t.Array(
		t.Object({
			serieId: t.String({
				descrpition: comment`
				Id on the external website.
				We store the serie's id because episode id are rarely stable.
			`,
			}),
			season: t.Integer(),
			link: t.Nullable(t.String({ format: "url" })),
		}),
	),
);
export type SeasonId = typeof SeasonId.static;
