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

/**
 * Join table: Anime -> Genres
 *
 * Source: AmqAnimeSchema.genres (string[])
 */
export const animeGenres = sqliteTable(
	"anime_genres",
	{
		annId: integer("ann_id")
			.notNull()
			.references(() => anime.annId, { onDelete: "cascade" }),
		genreName: text("genre_name")
			.notNull()
			.references(() => genres.name, { onDelete: "cascade" }),
	},
	(t) => ({
		pk: primaryKey({
			name: "anime_genres_pk",
			columns: [t.annId, t.genreName],
		}),
		animeIndex: index("anime_genres_ann_id_idx").on(t.annId),
		genreIndex: index("anime_genres_genre_name_idx").on(t.genreName),
	}),
);
