import type { Knex } from "knex";

export async function up(knex: Knex): Promise<void> {
  return knex.schema.createTable("users", (table) => {
    table.increments("id").primary();
    table.jsonb("user_details").notNullable();
    table.string("password").notNullable();
    table.timestamp("email_verified").nullable();
    table.string("stripe_id").nullable();
    table.string("verification_token", 255).nullable(); // ✅ FIXED
    table.timestamp("verification_token_expiry").nullable();
    table
      .enu("is_premium", ["logged_in", "guest", "premium"])
      .notNullable()
      .defaultTo("guest");
    table;
    table.enu("login_via", ["web", "google"]).notNullable().defaultTo("web");
    table
      .enu("status", ["active", "inactive", "suspended"])
      .notNullable()
      .defaultTo("active");

    table.timestamp("deleted_at").nullable(); // soft delete
    table.timestamp("created_at").defaultTo(knex.fn.now());
    table.timestamp("updated_at").defaultTo(knex.fn.now());
  });
}

export async function down(knex: Knex): Promise<void> {
  return knex.schema.dropTable("users");
}
