import { index, jsonb, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
import { agents } from "./agents.js";
import { organizations } from "./organizations.js";
export const approvals = pgTable("approvals", {
    id: uuid("id").primaryKey().defaultRandom(),
    orgId: uuid("org_id").notNull().references(() => organizations.id),
    type: text("type").notNull(),
    requestedByAgentId: uuid("requested_by_agent_id").references(() => agents.id),
    requestedByUserId: text("requested_by_user_id"),
    status: text("status").notNull().default("pending"),
    payload: jsonb("payload").$type().notNull(),
    decisionNote: text("decision_note"),
    decidedByUserId: text("decided_by_user_id"),
    decidedAt: timestamp("decided_at", { withTimezone: true }),
    createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
    updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
}, (table) => ({
    companyStatusTypeIdx: index("approvals_company_status_type_idx").on(table.orgId, table.status, table.type),
    companyUpdatedIdx: index("approvals_company_updated_idx").on(table.orgId, table.updatedAt),
    companyStatusUpdatedIdx: index("approvals_company_status_updated_idx").on(table.orgId, table.status, table.updatedAt),
}));
//# sourceMappingURL=approvals.js.map