import {
	index,
	integer,
	primaryKey,
	sqliteTable,
} from "drizzle-orm/sqlite-core";
import { artists } from "./artists";
import { groups } from "./groups";

/**
 * Join table: Artist -> Groups membership
 *
 * Source: AmqArtistSchema.inGroups
 */
export const artistGroups = sqliteTable(
	"artist_groups",
	{
		songArtistId: integer("song_artist_id")
			.notNull()
			.references(() => artists.songArtistId, {
				onDelete: "cascade",
			}),
		songGroupId: integer("song_group_id")
			.notNull()
			.references(() => groups.songGroupId, { onDelete: "cascade" }),
	},
	(t) => ({
		pk: primaryKey({
			name: "artist_groups_pk",
			columns: [t.songArtistId, t.songGroupId],
		}),
		artistIndex: index("artist_groups_artist_id_idx").on(t.songArtistId),
		groupIndex: index("artist_groups_group_id_idx").on(t.songGroupId),
	}),
);
