import { index, jsonb, pgTable, text, timestamp, uniqueIndex, uuid } from "drizzle-orm/pg-core";
import { organizations } from "./organizations.js";
export const principalPermissionGrants = pgTable("principal_permission_grants", {
    id: uuid("id").primaryKey().defaultRandom(),
    orgId: uuid("org_id").notNull().references(() => organizations.id),
    principalType: text("principal_type").notNull(),
    principalId: text("principal_id").notNull(),
    permissionKey: text("permission_key").notNull(),
    scope: jsonb("scope").$type(),
    grantedByUserId: text("granted_by_user_id"),
    createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
    updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
}, (table) => ({
    uniqueGrantIdx: uniqueIndex("principal_permission_grants_unique_idx").on(table.orgId, table.principalType, table.principalId, table.permissionKey),
    companyPermissionIdx: index("principal_permission_grants_company_permission_idx").on(table.orgId, table.permissionKey),
}));
//# sourceMappingURL=principal_permission_grants.js.map