import { MigrationInterface, QueryRunner } from 'typeorm';

export class WorkScheduleTimezone1780950000000 implements MigrationInterface {
  name = 'WorkScheduleTimezone1780950000000';

  public async up(queryRunner: QueryRunner): Promise<void> {
    const table = await queryRunner.getTable('working_schedule');
    const hasTimezone = table?.columns.some(
      (column) => column.name === 'timezone',
    );

    if (!hasTimezone) {
      await queryRunner.query(`
        ALTER TABLE \`working_schedule\`
          ADD COLUMN \`timezone\` VARCHAR(64) NOT NULL DEFAULT 'Asia/Dhaka' AFTER \`half_day_max_time\`
      `);
    }
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    const table = await queryRunner.getTable('working_schedule');
    const hasTimezone = table?.columns.some(
      (column) => column.name === 'timezone',
    );

    if (hasTimezone) {
      await queryRunner.query(`
        ALTER TABLE \`working_schedule\` DROP COLUMN \`timezone\`
      `);
    }
  }
}
