import { MigrationInterface, QueryRunner } from "typeorm"

export class AddHospitalTable1750250396352 implements MigrationInterface {
  name = "AddHospitalTable1750250396352"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "hospitals" ("id" SERIAL NOT NULL, "name" character varying NOT NULL, "address" text NOT NULL, "city_id" integer NOT NULL, "state_id" integer NOT NULL, "zip_code" character varying NOT NULL, "phone_number" character varying, "email" character varying, "is_partner" boolean NOT NULL DEFAULT false, "status" character varying NOT NULL DEFAULT 'active', "created_at" TIMESTAMP NOT NULL DEFAULT NOW(), "updated_at" TIMESTAMP NOT NULL DEFAULT NOW(), "deleted_at" TIMESTAMP, CONSTRAINT "PK_02738c80d71453bc3e369a01766" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "hospitals" ADD CONSTRAINT "FK_23c433920d6ce5dd61c2ac80f43" FOREIGN KEY ("city_id") REFERENCES "cities"("id") ON DELETE RESTRICT ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "hospitals" ADD CONSTRAINT "FK_d06e4729a033e4b3c3c00df3310" FOREIGN KEY ("state_id") REFERENCES "states"("id") ON DELETE RESTRICT ON UPDATE NO ACTION`,
    )
  }

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