import type { Knex } from "knex";

export async function up(knex: Knex): Promise<void> {
  return knex.schema.createTable("tool_pages", (table) => {
    table.increments("id").primary();
    table.string("tool_name").notNullable();
    table.string("page_slug").notNullable().unique();
    table
      .integer("lang")
      .unsigned()
      .notNullable()
      .references("id")
      .inTable("languages")
      .onDelete("CASCADE");
    table.string("meta_title").notNullable();
    table.string("meta_description").notNullable();
    table.string("page_file_name").notNullable().unique();
    table.string("title").notNullable();
    table.string("description").notNullable();
    table.boolean("is_active").notNullable().defaultTo(false);
    table
      .enum("is_index", ["index", "non_index"])
      .notNullable()
      .defaultTo("non_index");
    table.boolean("is_home_tool").notNullable().defaultTo(false);
    table.jsonb("page_keys").nullable();
    table.timestamp("created_at").defaultTo(knex.fn.now());
    table.timestamp("updated_at").defaultTo(knex.fn.now());
    table.timestamp("deleted_at").nullable(); // soft delete
  });
}

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