import { MigrationInterface, QueryRunner } from "typeorm"

export class AddServicePricingTable1755670144025 implements MigrationInterface {
  name = "AddServicePricingTable1755670144025"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "service_pricing" ("id" SERIAL NOT NULL, "plan_id" integer NOT NULL, "charge_type_id" integer NOT NULL, "city_id" integer, "service_type_id" integer NOT NULL, "price" character varying NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP, CONSTRAINT "PK_a9d4b6cf683e43141affcc43964" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "service_pricing" ADD CONSTRAINT "FK_2d8ee137fbd70742886f8f60d49" FOREIGN KEY ("plan_id") REFERENCES "pricing_plans"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "service_pricing" ADD CONSTRAINT "FK_20ac6b2cb63da123f176f9f1389" FOREIGN KEY ("charge_type_id") REFERENCES "charge_types"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "service_pricing" ADD CONSTRAINT "FK_e7c617cb773b6a7658fe6c16139" FOREIGN KEY ("city_id") REFERENCES "cities"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "service_pricing" ADD CONSTRAINT "FK_61528e9f517cd5ae476b55e501a" FOREIGN KEY ("service_type_id") REFERENCES "trip_types"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "service_pricing" DROP CONSTRAINT "FK_61528e9f517cd5ae476b55e501a"`,
    )
    await queryRunner.query(
      `ALTER TABLE "service_pricing" DROP CONSTRAINT "FK_e7c617cb773b6a7658fe6c16139"`,
    )
    await queryRunner.query(
      `ALTER TABLE "service_pricing" DROP CONSTRAINT "FK_20ac6b2cb63da123f176f9f1389"`,
    )
    await queryRunner.query(
      `ALTER TABLE "service_pricing" DROP CONSTRAINT "FK_2d8ee137fbd70742886f8f60d49"`,
    )
    await queryRunner.query(`DROP TABLE "service_pricing"`)
  }
}
