import { MigrationInterface, QueryRunner } from 'typeorm';

export class UserPrivilege1717385661972 implements MigrationInterface {
  name = 'UserPrivilege1717385661972';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "user_privilege_configurations" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "module" character varying(125) NOT NULL, "module_label" character varying(125), "menu" character varying(125) NOT NULL, "menu_label" character varying(125), "sub_menu" character varying(125), "sub_menu_label" character varying(125), "view" boolean, "create" boolean, "edit" boolean, "delete" boolean, "cancel" boolean, "confirm" boolean, "index" integer DEFAULT '0', "user_privilege_id" uuid, CONSTRAINT "PK_8ed47d7806c97dbf77969acc075" PRIMARY KEY ("id"))`,
    );
    await queryRunner.query(
      `CREATE TYPE "public"."user_privileges_status_enum" AS ENUM('active', 'cancel', 'confirmed', 'draft', 'expired', 'inactive', 'pending', 'refunded', 'rejected', 'settled', 'waiting')`,
    );
    await queryRunner.query(
      `CREATE TABLE "user_privileges" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "creator_id" character varying(36), "creator_name" character varying(125), "editor_id" character varying(36), "editor_name" character varying(125), "created_at" bigint NOT NULL, "updated_at" bigint NOT NULL, "status" "public"."user_privileges_status_enum" NOT NULL DEFAULT 'draft', "name" character varying(125) NOT NULL, CONSTRAINT "PK_4429e115dd3db86b6cf1f044ea5" PRIMARY KEY ("id"))`,
    );
    await queryRunner.query(
      `ALTER TABLE "user_privilege_configurations" ADD CONSTRAINT "FK_ef45354482245798d95f78e450a" FOREIGN KEY ("user_privilege_id") REFERENCES "user_privileges"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "user_privilege_configurations" DROP CONSTRAINT "FK_ef45354482245798d95f78e450a"`,
    );
    await queryRunner.query(`DROP TABLE "user_privileges"`);
    await queryRunner.query(`DROP TYPE "public"."user_privileges_status_enum"`);
    await queryRunner.query(`DROP TABLE "user_privilege_configurations"`);
  }
}
