import {
	index,
	integer,
	sqliteTable,
	text,
	uniqueIndex,
} from "drizzle-orm/sqlite-core";
import { anime } from "./anime";

/**
 * Additional localized/alternative names for an anime.
 *
 * Source: AmqAnimeSchema.names
 * - language: "EN" | "JA" (per source)
 * - name: string
 */
export const animeNames = sqliteTable(
	"anime_names",
	{
		id: integer("id").notNull().primaryKey({ autoIncrement: true }),

		annId: integer("ann_id")
			.notNull()
			.references(() => anime.annId, { onDelete: "cascade" }),

		/** "EN" | "JA" per source */
		language: text("language").notNull(),

		name: text("name").notNull(),
	},
	(t) => ({
		animeIndex: index("anime_names_ann_id_idx").on(t.annId),
		nameIndex: index("anime_names_name_idx").on(t.name),
		uniquePerAnime: uniqueIndex("anime_names_ann_lang_name_uq").on(
			t.annId,
			t.language,
			t.name,
		),
	}),
);
