import { userTable } from "../user/user.sql.js";
import { orgTable } from "../organisation/org.sql.js";
import { pgEnum, pgTable } from "drizzle-orm/pg-core";
import { id, ulid, timestamps } from "../drizzle/types.js";

export const MemberRole = pgEnum("role", ["admin", "member", "admin"]);

export const memberTable = pgTable("members", {
  ...id,
  ...timestamps,
  orgID: ulid("organisation_id")
    .references(() => orgTable.id, {
      onDelete: "cascade",
    })
    .notNull(),
  ownerID: ulid("owner_id")
    .references(() => userTable.id, {
      onDelete: "cascade",
    })
    .notNull(),
  role: MemberRole("role").notNull(),
});
