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

/**
 * Join table: Group -> Artist members
 *
 * Source: AmqGroupSchema.artistMembers
 */
export const groupArtistMembers = sqliteTable(
	"group_artist_members",
	{
		songGroupId: integer("song_group_id")
			.notNull()
			.references(() => groups.songGroupId, { onDelete: "cascade" }),
		songArtistId: integer("song_artist_id")
			.notNull()
			.references(() => artists.songArtistId, {
				onDelete: "cascade",
			}),
	},
	(t) => ({
		pk: primaryKey({
			name: "group_artist_members_pk",
			columns: [t.songGroupId, t.songArtistId],
		}),
		groupIndex: index("group_artist_members_group_id_idx").on(t.songGroupId),
		artistIndex: index("group_artist_members_artist_id_idx").on(t.songArtistId),
	}),
);
