import { MigrationInterface, QueryRunner } from 'typeorm'

export class AddReservationEntity1697709033367 implements MigrationInterface {
	name = 'AddReservationEntity1697709033367'

	public async up(queryRunner: QueryRunner): Promise<void> {
		await queryRunner.query(
			`CREATE TYPE "public"."reservation_state_enum" AS ENUM('unconfirmed', 'approved', 'rejected', 'seated', 'done')`,
		)
		await queryRunner.query(
			`CREATE TABLE "reservation" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "tenantId" uuid, "createdBy" uuid, "lastUpdatedAt" TIMESTAMP NOT NULL DEFAULT now(), "lastUpdatedBy" uuid, "noOfPersons" integer NOT NULL, "startDate" TIMESTAMP WITH TIME ZONE NOT NULL, "endDate" TIMESTAMP WITH TIME ZONE NOT NULL, "state" "public"."reservation_state_enum" NOT NULL DEFAULT 'unconfirmed', "comment" text, "reminderSent" boolean NOT NULL DEFAULT false, "tableId" uuid, "customerName" character varying(60) NOT NULL, "customerEmail" text, "customerPhonenumber" text, CONSTRAINT "PK_48b1f9922368359ab88e8bfa525" PRIMARY KEY ("id"))`,
		)
		await queryRunner.query(
			`ALTER TABLE "reservation" ADD CONSTRAINT "FK_d221f3398a0352970306b3dc676" FOREIGN KEY ("tableId") REFERENCES "table"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
		)
	}

	public async down(queryRunner: QueryRunner): Promise<void> {
		await queryRunner.query(`ALTER TABLE "reservation" DROP CONSTRAINT "FK_d221f3398a0352970306b3dc676"`)
		await queryRunner.query(`DROP TABLE "reservation"`)
		await queryRunner.query(`DROP TYPE "public"."reservation_state_enum"`)
	}
}
