import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';

export class AddGeoAndTrashToBlogPosts1748000000000 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.addColumns('blog_posts', [
      // GEO (Generative Engine Optimisation) fields
      new TableColumn({
        name: 'ai_summary',
        type: 'text',
        isNullable: true,
      }),
      new TableColumn({
        name: 'faq',
        type: 'jsonb',
        isNullable: false,
        default: "'[]'",
      }),
      new TableColumn({
        name: 'key_takeaways',
        type: 'jsonb',
        isNullable: false,
        default: "'[]'",
      }),
      new TableColumn({
        name: 'ai_entities',
        type: 'jsonb',
        isNullable: false,
        default: "'[]'",
      }),
      // Soft delete (trash)
      new TableColumn({
        name: 'deleted_at',
        type: 'timestamp',
        isNullable: true,
      }),
    ]);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.dropColumns('blog_posts', [
      'ai_summary',
      'faq',
      'key_takeaways',
      'ai_entities',
      'deleted_at',
    ]);
  }
}
