// src/server/entities/permissions.ts
import { text, boolean, index } from "drizzle-orm/pg-core";
import { id, timestamps } from "@spfn/core/db";

// src/server/entities/schema.ts
import { createFunctionSchema } from "@spfn/core/db";
var authSchema = createFunctionSchema("@spfn/auth");

// src/server/entities/permissions.ts
var permissions = authSchema.table(
  "permissions",
  {
    // Primary key
    id: id(),
    // Permission identifier (e.g., 'user:delete', 'post:publish')
    // Format: resource:action or namespace:resource:action
    // Must be unique
    name: text("name").notNull().unique(),
    // Display name for UI
    displayName: text("display_name").notNull(),
    // Permission description
    description: text("description"),
    // Category for grouping (e.g., 'user', 'post', 'admin', 'system')
    category: text("category"),
    // Built-in permission flag
    // true: Core package permissions - cannot be deleted
    // false: Custom or preset permissions
    isBuiltin: boolean("is_builtin").notNull().default(false),
    // System permission flag
    // true: Defined in code (builtin or preset)
    // false: Runtime created custom permission
    isSystem: boolean("is_system").notNull().default(false),
    // Active status
    // false: Deactivated permission (not enforced)
    isActive: boolean("is_active").notNull().default(true),
    ...timestamps()
  },
  (table) => [
    index("permissions_name_idx").on(table.name),
    index("permissions_category_idx").on(table.category),
    index("permissions_is_system_idx").on(table.isSystem),
    index("permissions_is_active_idx").on(table.isActive),
    index("permissions_is_builtin_idx").on(table.isBuiltin)
  ]
);
export {
  permissions
};
//# sourceMappingURL=permissions.js.map