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

/**
 * Join table: Group -> Group members
 *
 * Source: AmqGroupSchema.groupMembers
 */
export const groupGroupMembers = sqliteTable(
	"group_group_members",
	{
		songGroupId: integer("song_group_id")
			.notNull()
			.references(() => groups.songGroupId, { onDelete: "cascade" }),
		memberSongGroupId: integer("member_song_group_id")
			.notNull()
			.references(() => groups.songGroupId, { onDelete: "cascade" }),
	},
	(t) => ({
		pk: primaryKey({
			name: "group_group_members_pk",
			columns: [t.songGroupId, t.memberSongGroupId],
		}),
		groupIndex: index("group_group_members_group_id_idx").on(t.songGroupId),
		memberIndex: index("group_group_members_member_group_id_idx").on(
			t.memberSongGroupId,
		),
	}),
);
