import { MigrationInterface, QueryRunner } from "typeorm";

export class Migrations1738930140723 implements MigrationInterface {
    name = 'Migrations1738930140723'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`CREATE TABLE "dispute-history" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "reason" text NOT NULL DEFAULT '', "description" text NOT NULL DEFAULT '', "attachment" jsonb, "created_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "updated_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP(0), "dispute_by" uuid, "dispute_id" uuid, CONSTRAINT "PK_cf00ab1b1c1381c2dfd04b302b9" PRIMARY KEY ("id"))`);
        await queryRunner.query(`CREATE TYPE "public"."dispute_winner_enum" AS ENUM('brand', 'influencer')`);
        await queryRunner.query(`CREATE TABLE "dispute" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "is_influencer_despute" boolean NOT NULL DEFAULT false, "is_brand_despute" boolean NOT NULL DEFAULT false, "winner" "public"."dispute_winner_enum", "message" text NOT NULL DEFAULT '', "solved_by" character varying, "created_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "updated_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP(0), "influencer_id" uuid, "brand_id" uuid, "campaign_influencer_id" uuid, CONSTRAINT "PK_e2f1f4741f2094ce789b0a7c5b3" PRIMARY KEY ("id"))`);
        await queryRunner.query(`ALTER TABLE "dispute-history" ADD CONSTRAINT "FK_a92afe350f3d539f0c3bb0f82a3" FOREIGN KEY ("dispute_by") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "dispute-history" ADD CONSTRAINT "FK_d8a0fcbb19fd9db1f5173f344a1" FOREIGN KEY ("dispute_id") REFERENCES "dispute"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "dispute" ADD CONSTRAINT "FK_2853670f069e23a66cf9cfa51dc" FOREIGN KEY ("influencer_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "dispute" ADD CONSTRAINT "FK_1413bb310c3208ec82e2cf17415" FOREIGN KEY ("brand_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "dispute" ADD CONSTRAINT "FK_5c65d33e7172f749001cb97e023" FOREIGN KEY ("campaign_influencer_id") REFERENCES "campaign_influencers"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "dispute" DROP CONSTRAINT "FK_5c65d33e7172f749001cb97e023"`);
        await queryRunner.query(`ALTER TABLE "dispute" DROP CONSTRAINT "FK_1413bb310c3208ec82e2cf17415"`);
        await queryRunner.query(`ALTER TABLE "dispute" DROP CONSTRAINT "FK_2853670f069e23a66cf9cfa51dc"`);
        await queryRunner.query(`ALTER TABLE "dispute-history" DROP CONSTRAINT "FK_d8a0fcbb19fd9db1f5173f344a1"`);
        await queryRunner.query(`ALTER TABLE "dispute-history" DROP CONSTRAINT "FK_a92afe350f3d539f0c3bb0f82a3"`);
        await queryRunner.query(`DROP TABLE "dispute"`);
        await queryRunner.query(`DROP TYPE "public"."dispute_winner_enum"`);
        await queryRunner.query(`DROP TABLE "dispute-history"`);
    }

}
