import { MigrationInterface, QueryRunner } from "typeorm";

export class Migrations1737538627210 implements MigrationInterface {
    name = 'Migrations1737538627210'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`CREATE TABLE "draft_comments" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "comment" character varying, "created_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "updated_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP(0), "draft_id" uuid, "from_user_id" uuid, CONSTRAINT "PK_f7f086bca30fc58e7411216785e" PRIMARY KEY ("id"))`);
        await queryRunner.query(`CREATE TYPE "public"."draft_status_enum" AS ENUM('approved', 'pending', 'rejected')`);
        await queryRunner.query(`CREATE TABLE "draft" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "status" "public"."draft_status_enum" NOT NULL DEFAULT 'pending', "influencer_budget" integer NOT NULL DEFAULT '0', "created_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "updated_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP(0), "campaign_id" uuid, "influencerId" uuid, CONSTRAINT "PK_0b2b03d3f2c998450423648bc65" PRIMARY KEY ("id"))`);
        await queryRunner.query(`CREATE TABLE "draft_versions" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "draft_name" character varying, "created_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "updated_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP(0), "draft_id" uuid, CONSTRAINT "PK_eb1ffdb8f52739cb76a94656883" PRIMARY KEY ("id"))`);
        await queryRunner.query(`ALTER TABLE "draft_versions" DROP COLUMN "created_at"`);
        await queryRunner.query(`ALTER TABLE "draft_versions" DROP COLUMN "updated_at"`);
        await queryRunner.query(`ALTER TABLE "draft_versions" DROP COLUMN "deleted_at"`);
        await queryRunner.query(`ALTER TABLE "draft" DROP COLUMN "created_at"`);
        await queryRunner.query(`ALTER TABLE "draft" DROP COLUMN "updated_at"`);
        await queryRunner.query(`ALTER TABLE "draft" DROP COLUMN "deleted_at"`);
        await queryRunner.query(`ALTER TABLE "draft" ADD "created_at" TIMESTAMP(0) NOT NULL DEFAULT now()`);
        await queryRunner.query(`ALTER TABLE "draft" ADD "updated_at" TIMESTAMP(0) NOT NULL DEFAULT now()`);
        await queryRunner.query(`ALTER TABLE "draft" ADD "deleted_at" TIMESTAMP(0)`);
        await queryRunner.query(`ALTER TABLE "draft_versions" ADD "created_at" TIMESTAMP(0) NOT NULL DEFAULT now()`);
        await queryRunner.query(`ALTER TABLE "draft_versions" ADD "updated_at" TIMESTAMP(0) NOT NULL DEFAULT now()`);
        await queryRunner.query(`ALTER TABLE "draft_versions" ADD "deleted_at" TIMESTAMP(0)`);
        await queryRunner.query(`ALTER TABLE "draft_versions" ADD "createdAt" TIMESTAMP NOT NULL DEFAULT now()`);
        await queryRunner.query(`ALTER TABLE "draft_versions" ADD "updatedAt" TIMESTAMP NOT NULL DEFAULT now()`);
        await queryRunner.query(`ALTER TABLE "draft" ADD "createdAt" TIMESTAMP NOT NULL DEFAULT now()`);
        await queryRunner.query(`ALTER TABLE "draft" ADD "updatedAt" TIMESTAMP NOT NULL DEFAULT now()`);
        await queryRunner.query(`ALTER TABLE "draft_comments" ADD CONSTRAINT "FK_59ae9307fd671b2bdb558df9ea5" FOREIGN KEY ("draft_id") REFERENCES "draft"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "draft_comments" ADD CONSTRAINT "FK_27a9c00138a6b14af44f5bd1df3" FOREIGN KEY ("from_user_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "draft" ADD CONSTRAINT "FK_46bf237252d88cf2923d2a839a6" FOREIGN KEY ("campaign_id") REFERENCES "campaigns"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "draft" ADD CONSTRAINT "FK_834096cdf598db00992d3c1688d" FOREIGN KEY ("influencerId") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "draft_versions" ADD CONSTRAINT "FK_70d9a9c8434da405890a7182abe" FOREIGN KEY ("draft_id") REFERENCES "draft"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "draft_versions" DROP CONSTRAINT "FK_70d9a9c8434da405890a7182abe"`);
        await queryRunner.query(`ALTER TABLE "draft" DROP CONSTRAINT "FK_834096cdf598db00992d3c1688d"`);
        await queryRunner.query(`ALTER TABLE "draft" DROP CONSTRAINT "FK_46bf237252d88cf2923d2a839a6"`);
        await queryRunner.query(`ALTER TABLE "draft_comments" DROP CONSTRAINT "FK_27a9c00138a6b14af44f5bd1df3"`);
        await queryRunner.query(`ALTER TABLE "draft_comments" DROP CONSTRAINT "FK_59ae9307fd671b2bdb558df9ea5"`);
        await queryRunner.query(`ALTER TABLE "draft" DROP COLUMN "updatedAt"`);
        await queryRunner.query(`ALTER TABLE "draft" DROP COLUMN "createdAt"`);
        await queryRunner.query(`ALTER TABLE "draft_versions" DROP COLUMN "updatedAt"`);
        await queryRunner.query(`ALTER TABLE "draft_versions" DROP COLUMN "createdAt"`);
        await queryRunner.query(`ALTER TABLE "draft_versions" DROP COLUMN "deleted_at"`);
        await queryRunner.query(`ALTER TABLE "draft_versions" DROP COLUMN "updated_at"`);
        await queryRunner.query(`ALTER TABLE "draft_versions" DROP COLUMN "created_at"`);
        await queryRunner.query(`ALTER TABLE "draft" DROP COLUMN "deleted_at"`);
        await queryRunner.query(`ALTER TABLE "draft" DROP COLUMN "updated_at"`);
        await queryRunner.query(`ALTER TABLE "draft" DROP COLUMN "created_at"`);
        await queryRunner.query(`ALTER TABLE "draft" ADD "deleted_at" TIMESTAMP(0)`);
        await queryRunner.query(`ALTER TABLE "draft" ADD "updated_at" TIMESTAMP(0) NOT NULL DEFAULT now()`);
        await queryRunner.query(`ALTER TABLE "draft" ADD "created_at" TIMESTAMP(0) NOT NULL DEFAULT now()`);
        await queryRunner.query(`ALTER TABLE "draft_versions" ADD "deleted_at" TIMESTAMP(0)`);
        await queryRunner.query(`ALTER TABLE "draft_versions" ADD "updated_at" TIMESTAMP(0) NOT NULL DEFAULT now()`);
        await queryRunner.query(`ALTER TABLE "draft_versions" ADD "created_at" TIMESTAMP(0) NOT NULL DEFAULT now()`);
        await queryRunner.query(`DROP TABLE "draft_versions"`);
        await queryRunner.query(`DROP TABLE "draft"`);
        await queryRunner.query(`DROP TYPE "public"."draft_status_enum"`);
        await queryRunner.query(`DROP TABLE "draft_comments"`);
    }

}
