import { MigrationInterface, QueryRunner } from "typeorm"

export class AddVehicleInsurancesEntity1749039266837 implements MigrationInterface {
  name = "AddVehicleInsurancesEntity1749039266837"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "vehicle_insurances" ("id" SERIAL NOT NULL, "fleet_id" integer NOT NULL, "policy_number" character varying NOT NULL, "insurance_provider" character varying NOT NULL, "coverage_type" character varying NOT NULL, "start_date" date NOT NULL, "end_date" date NOT NULL, "is_active_policy" boolean NOT NULL DEFAULT false, "document_file" character varying, "created_at" TIMESTAMP NOT NULL DEFAULT NOW(), "updated_at" TIMESTAMP NOT NULL DEFAULT NOW(), "deleted_at" TIMESTAMP, CONSTRAINT "UQ_a09cb9702eee8e3d680bb046fa9" UNIQUE ("policy_number"), CONSTRAINT "PK_a9356b390eea0f50cd1089b178c" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "vehicle_insurances" ADD CONSTRAINT "FK_1e67ed65191d1ae0692346129e7" FOREIGN KEY ("fleet_id") REFERENCES "fleet_operations"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "vehicle_insurances" DROP CONSTRAINT "FK_1e67ed65191d1ae0692346129e7"`,
    )
    await queryRunner.query(`DROP TABLE "vehicle_insurances"`)
  }
}
