// src/server/entities/verification-codes.ts
import { text, timestamp, 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/verification-codes.ts
var verificationCodes = authSchema.table(
  "verification_codes",
  {
    id: id(),
    // Target (email or phone)
    target: text("target").notNull(),
    // Email address or E.164 phone number
    targetType: text(
      "target_type",
      {
        enum: ["email", "phone"]
      }
    ).notNull(),
    // Code
    code: text("code").notNull(),
    // 6-digit code by default (configurable)
    // Purpose
    purpose: text(
      "purpose",
      {
        enum: ["registration", "login", "password_reset", "email_change", "phone_change"]
      }
    ).notNull(),
    // Expiry
    expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
    // Usage tracking
    usedAt: timestamp("used_at", { withTimezone: true }),
    attempts: text("attempts").notNull().default("0"),
    // Track failed verification attempts
    ...timestamps()
  },
  (table) => [
    // Index for quick lookup by target and purpose
    index("target_purpose_idx").on(table.target, table.purpose, table.expiresAt)
  ]
);
export {
  verificationCodes
};
//# sourceMappingURL=verification-codes.js.map