/*
  Warnings:

  - You are about to drop the `account_trouble_approve_request` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `account_trouble_approve_request_entity` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `account_trouble_approve_request_entity_account` table. If the table is not empty, all the data it contains will be lost.

*/
-- CreateEnum
CREATE TYPE "AccountIssueRequestIssueType" AS ENUM ('PAYMENT_ISSUE', 'SPEND_ISSUE', 'CANCEL', 'UNBLOCK', 'OTHER');

-- DropForeignKey
ALTER TABLE "account_trouble_approve_request" DROP CONSTRAINT "account_trouble_approve_request_requestId_fkey";

-- DropForeignKey
ALTER TABLE "account_trouble_approve_request_entity" DROP CONSTRAINT "account_trouble_approve_request_entity_accountTroubleReque_fkey";

-- DropForeignKey
ALTER TABLE "account_trouble_approve_request_entity_account" DROP CONSTRAINT "account_trouble_approve_request_entity_account_accountId_fkey";

-- DropForeignKey
ALTER TABLE "account_trouble_approve_request_entity_account" DROP CONSTRAINT "account_trouble_approve_request_entity_account_accountTrou_fkey";

-- DropTable
DROP TABLE "account_trouble_approve_request";

-- DropTable
DROP TABLE "account_trouble_approve_request_entity";

-- DropTable
DROP TABLE "account_trouble_approve_request_entity_account";

-- DropEnum
DROP TYPE "AccountTroubleRequestIssueType";

-- CreateTable
CREATE TABLE "account_issue_approve_request" (
    "id" SERIAL NOT NULL,
    "requestId" INTEGER NOT NULL
);

-- CreateTable
CREATE TABLE "account_issue_approve_request_entity" (
    "id" SERIAL NOT NULL,
    "issueType" "AccountIssueRequestIssueType" NOT NULL,
    "bmExternalId" TEXT NOT NULL,
    "accountId" INTEGER NOT NULL,
    "accountIssueRequestId" INTEGER NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "account_issue_approve_request_id_key" ON "account_issue_approve_request"("id");

-- CreateIndex
CREATE UNIQUE INDEX "account_issue_approve_request_requestId_key" ON "account_issue_approve_request"("requestId");

-- CreateIndex
CREATE UNIQUE INDEX "account_issue_approve_request_entity_id_key" ON "account_issue_approve_request_entity"("id");

-- AddForeignKey
ALTER TABLE "account_issue_approve_request" ADD CONSTRAINT "account_issue_approve_request_requestId_fkey" FOREIGN KEY ("requestId") REFERENCES "request"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "account_issue_approve_request_entity" ADD CONSTRAINT "account_issue_approve_request_entity_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "account"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "account_issue_approve_request_entity" ADD CONSTRAINT "account_issue_approve_request_entity_accountIssueRequestId_fkey" FOREIGN KEY ("accountIssueRequestId") REFERENCES "account_issue_approve_request"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
