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

export class AddOrganizationContactFields1733000000000 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    // Add siren column
    await queryRunner.addColumn(
      'organizations',
      new TableColumn({
        name: 'siren',
        type: 'char',
        length: '9',
        isNullable: true,
      })
    );

    // Add eori column
    await queryRunner.addColumn(
      'organizations',
      new TableColumn({
        name: 'eori',
        type: 'varchar',
        length: '17',
        isNullable: true,
      })
    );

    // Add contact_phone column
    await queryRunner.addColumn(
      'organizations',
      new TableColumn({
        name: 'contact_phone',
        type: 'varchar',
        length: '50',
        isNullable: true,
      })
    );

    // Add contact_email column
    await queryRunner.addColumn(
      'organizations',
      new TableColumn({
        name: 'contact_email',
        type: 'varchar',
        length: '255',
        isNullable: true,
      })
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.dropColumn('organizations', 'contact_email');
    await queryRunner.dropColumn('organizations', 'contact_phone');
    await queryRunner.dropColumn('organizations', 'eori');
    await queryRunner.dropColumn('organizations', 'siren');
  }
}
