import { sql } from "drizzle-orm";
import { index, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";

export const adminRequest = sqliteTable(
	"admin_request",
	{
		id: text("id").primaryKey(),
		userId: text("user_id").notNull().unique(),
		status: text("status").default("pending").notNull(), // pending, approved, rejected
		requestedAt: integer("requested_at", { mode: "timestamp_ms" })
			.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
			.notNull(),
		reviewedAt: integer("reviewed_at", { mode: "timestamp_ms" }),
		reviewedBy: text("reviewed_by"),
	},
	(table) => [
		index("admin_request_userId_idx").on(table.userId),
		index("admin_request_status_idx").on(table.status),
	],
);

export type AdminRequest = typeof adminRequest.$inferSelect;
export type NewAdminRequest = typeof adminRequest.$inferInsert;
