'use strict';

var pgCore = require('drizzle-orm/pg-core');
var drizzleOrm = require('drizzle-orm');

// src/auth/schema/enums.ts
var userRole = pgCore.pgEnum("UserRole", ["USER", "ADMIN", "SUPER_ADMIN"]);
var user = pgCore.pgTable(
  "User",
  {
    id: pgCore.text().primaryKey().notNull(),
    email: pgCore.text().notNull(),
    emailVerified: pgCore.boolean().default(false).notNull(),
    username: pgCore.text().notNull(),
    password: pgCore.text(),
    name: pgCore.text(),
    nickname: pgCore.text(),
    image: pgCore.text(),
    avatar: pgCore.text(),
    role: userRole().default("USER").notNull(),
    preferences: pgCore.jsonb(),
    createdAt: pgCore.timestamp({ precision: 3, mode: "string" }).default(drizzleOrm.sql`CURRENT_TIMESTAMP`).notNull(),
    updatedAt: pgCore.timestamp({ precision: 3, mode: "string" }).notNull(),
    twoFactorEnabled: pgCore.boolean().default(false).notNull()
  },
  (table) => [
    pgCore.uniqueIndex("User_email_key").using("btree", table.email.asc().nullsLast().op("text_ops")),
    pgCore.uniqueIndex("User_username_key").using(
      "btree",
      table.username.asc().nullsLast().op("text_ops")
    )
  ]
);
var session = pgCore.pgTable(
  "Session",
  {
    id: pgCore.text().primaryKey().notNull(),
    userId: pgCore.text().notNull(),
    token: pgCore.text().notNull(),
    expiresAt: pgCore.timestamp({ precision: 3, mode: "string" }).notNull(),
    ipAddress: pgCore.text(),
    userAgent: pgCore.text(),
    createdAt: pgCore.timestamp({ precision: 3, mode: "string" }).default(drizzleOrm.sql`CURRENT_TIMESTAMP`).notNull(),
    updatedAt: pgCore.timestamp({ precision: 3, mode: "string" }).default(drizzleOrm.sql`CURRENT_TIMESTAMP`).notNull()
  },
  (table) => [
    pgCore.uniqueIndex("Session_token_key").using("btree", table.token.asc().nullsLast().op("text_ops")),
    pgCore.foreignKey({
      columns: [table.userId],
      foreignColumns: [user.id],
      name: "Session_userId_fkey"
    }).onUpdate("cascade").onDelete("cascade")
  ]
);
var account = pgCore.pgTable(
  "Account",
  {
    id: pgCore.text().primaryKey().notNull(),
    accountId: pgCore.text().notNull(),
    providerId: pgCore.text().notNull(),
    // 提供商: github, google, wechat 等
    userId: pgCore.text().notNull(),
    accessToken: pgCore.text(),
    refreshToken: pgCore.text(),
    idToken: pgCore.text(),
    accessTokenExpiresAt: pgCore.timestamp({ precision: 3, mode: "string" }),
    refreshTokenExpiresAt: pgCore.timestamp({ precision: 3, mode: "string" }),
    scope: pgCore.text(),
    password: pgCore.text(),
    createdAt: pgCore.timestamp({ precision: 3, mode: "string" }).default(drizzleOrm.sql`CURRENT_TIMESTAMP`).notNull(),
    updatedAt: pgCore.timestamp({ precision: 3, mode: "string" }).notNull()
  },
  (table) => [
    pgCore.uniqueIndex("Account_providerId_accountId_key").using(
      "btree",
      table.providerId.asc().nullsLast().op("text_ops"),
      table.accountId.asc().nullsLast().op("text_ops")
    ),
    pgCore.foreignKey({
      columns: [table.userId],
      foreignColumns: [user.id],
      name: "Account_userId_fkey"
    }).onUpdate("cascade").onDelete("cascade")
  ]
);
var verifications = pgCore.pgTable(
  "verifications",
  {
    id: pgCore.text().primaryKey().notNull(),
    identifier: pgCore.text().notNull(),
    // 邮箱或手机号
    value: pgCore.text().notNull(),
    // 验证码
    expiresAt: pgCore.timestamp({ precision: 3, mode: "string" }).notNull(),
    createdAt: pgCore.timestamp({ precision: 3, mode: "string" }).default(drizzleOrm.sql`CURRENT_TIMESTAMP`).notNull()
  },
  (table) => [
    pgCore.uniqueIndex("verifications_identifier_value_key").using(
      "btree",
      table.identifier.asc().nullsLast().op("text_ops"),
      table.value.asc().nullsLast().op("text_ops")
    )
  ]
);
var userRelations = drizzleOrm.relations(user, ({ many }) => ({
  sessions: many(session),
  accounts: many(account)
}));
var sessionRelations = drizzleOrm.relations(session, ({ one }) => ({
  user: one(user, {
    fields: [session.userId],
    references: [user.id]
  })
}));
var accountRelations = drizzleOrm.relations(account, ({ one }) => ({
  user: one(user, {
    fields: [account.userId],
    references: [user.id]
  })
}));

exports.account = account;
exports.accountRelations = accountRelations;
exports.session = session;
exports.sessionRelations = sessionRelations;
exports.user = user;
exports.userRelations = userRelations;
exports.userRole = userRole;
exports.verifications = verifications;
//# sourceMappingURL=chunk-SVWQN2LR.js.map
//# sourceMappingURL=chunk-SVWQN2LR.js.map