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

/**
 * Join table: Anime -> Tags
 *
 * Source: AmqAnimeSchema.tags (string[])
 */
export const animeTags = sqliteTable(
	"anime_tags",
	{
		annId: integer("ann_id")
			.notNull()
			.references(() => anime.annId, { onDelete: "cascade" }),
		tagName: text("tag_name")
			.notNull()
			.references(() => tags.name, { onDelete: "cascade" }),
	},
	(t) => ({
		pk: primaryKey({
			name: "anime_tags_pk",
			columns: [t.annId, t.tagName],
		}),
		animeIndex: index("anime_tags_ann_id_idx").on(t.annId),
		tagIndex: index("anime_tags_tag_name_idx").on(t.tagName),
	}),
);
