import { pgTable, text, timestamp, uuid, pgEnum } from "drizzle-orm/pg-core";
import { users } from "./auth";
import { familyGroups } from "./subscription";
import { familyMemberRole } from "./enums";

export const invitationStatus = pgEnum("invitation_status", ["pending", "accepted", "expired", "cancelled"]);

export const invitations = pgTable("invitations", {
  id: uuid("id").defaultRandom().primaryKey(),
  groupId: uuid("group_id").notNull().references(() => familyGroups.id, { onDelete: "cascade" }),
  email: text("email").notNull(),
  role: familyMemberRole("role").default("member").notNull(),
  invitedBy: uuid("invited_by").notNull().references(() => users.id),
  status: invitationStatus("status").default("pending").notNull(),
  expiresAt: timestamp("expires_at", { withTimezone: true, mode: "date" }).notNull(),
  createdAt: timestamp("created_at", { withTimezone: true, mode: "date" }).defaultNow().notNull(),
  updatedAt: timestamp("updated_at", { withTimezone: true, mode: "date" }).defaultNow().notNull().$onUpdate(() => new Date()),
});
