import { MigrationInterface, QueryRunner } from "typeorm"

export class AlterInspectionReportEntity1753441408234 implements MigrationInterface {
  name = "AlterInspectionReportEntity1753441408234"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "inspection_fleet_answers" DROP CONSTRAINT "FK_1641a936f0cffb8196a12bdd556"`,
    )
    await queryRunner.query(
      `ALTER TABLE "inspection_fleet_answers" DROP CONSTRAINT "FK_2aa09e9f4c516a719daed92732a"`,
    )
    await queryRunner.query(
      `ALTER TABLE "inspection_fleet_answers" DROP CONSTRAINT "FK_bbd371764ce252a5f867ca5f5bc"`,
    )
    await queryRunner.query(
      `ALTER TABLE "inspection_fleet_answers" ALTER COLUMN "inspection_fleet_report_id" DROP NOT NULL`,
    )
    await queryRunner.query(
      `ALTER TABLE "inspection_fleet_answers" ALTER COLUMN "question_id" DROP NOT NULL`,
    )
    await queryRunner.query(
      `ALTER TABLE "inspection_fleet_answers" ALTER COLUMN "selected_answer_id" DROP NOT NULL`,
    )
    await queryRunner.query(
      `ALTER TABLE "inspection_fleet_answers" ADD CONSTRAINT "FK_2aa09e9f4c516a719daed92732a" FOREIGN KEY ("inspection_fleet_report_id") REFERENCES "inspection_fleet_reports"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "inspection_fleet_answers" ADD CONSTRAINT "FK_bbd371764ce252a5f867ca5f5bc" FOREIGN KEY ("question_id") REFERENCES "inspection_questions"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "inspection_fleet_answers" ADD CONSTRAINT "FK_1641a936f0cffb8196a12bdd556" FOREIGN KEY ("selected_answer_id") REFERENCES "inspection_answer_options"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
    )
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "inspection_fleet_answers" DROP CONSTRAINT "FK_1641a936f0cffb8196a12bdd556"`,
    )
    await queryRunner.query(
      `ALTER TABLE "inspection_fleet_answers" DROP CONSTRAINT "FK_bbd371764ce252a5f867ca5f5bc"`,
    )
    await queryRunner.query(
      `ALTER TABLE "inspection_fleet_answers" DROP CONSTRAINT "FK_2aa09e9f4c516a719daed92732a"`,
    )
    await queryRunner.query(
      `ALTER TABLE "inspection_fleet_answers" ALTER COLUMN "selected_answer_id" SET NOT NULL`,
    )
    await queryRunner.query(
      `ALTER TABLE "inspection_fleet_answers" ALTER COLUMN "question_id" SET NOT NULL`,
    )
    await queryRunner.query(
      `ALTER TABLE "inspection_fleet_answers" ALTER COLUMN "inspection_fleet_report_id" SET NOT NULL`,
    )
    await queryRunner.query(
      `ALTER TABLE "inspection_fleet_answers" ADD CONSTRAINT "FK_bbd371764ce252a5f867ca5f5bc" FOREIGN KEY ("question_id") REFERENCES "inspection_questions"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "inspection_fleet_answers" ADD CONSTRAINT "FK_2aa09e9f4c516a719daed92732a" FOREIGN KEY ("inspection_fleet_report_id") REFERENCES "inspection_fleet_reports"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "inspection_fleet_answers" ADD CONSTRAINT "FK_1641a936f0cffb8196a12bdd556" FOREIGN KEY ("selected_answer_id") REFERENCES "inspection_answer_options"("id") ON DELETE SET NULL ON UPDATE NO ACTION`,
    )
  }
}
