/*
  Warnings:

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

*/
-- CreateEnum
CREATE TYPE "EmailAccessAction" AS ENUM ('REMOVE', 'ADD');

-- CreateEnum
CREATE TYPE "AccountManagerRequestType" AS ENUM ('CREATE_ACCOUNT', 'TRANSFER_PIXEL', 'UNLOCK_ACCOUNT', 'EMAIL_ACCESS');

-- DropForeignKey
ALTER TABLE "account_finanace_reques" DROP CONSTRAINT "account_finanace_reques_accountId_fkey";

-- DropForeignKey
ALTER TABLE "account_finanace_reques" DROP CONSTRAINT "account_finanace_reques_userId_fkey";

-- DropTable
DROP TABLE "account_finanace_reques";

-- CreateTable
CREATE TABLE "account_finanace_request" (
    "id" SERIAL NOT NULL,
    "createDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updateDate" TIMESTAMP(3) NOT NULL,
    "note" TEXT,
    "status" "AccountFinanceRequestStatus" NOT NULL DEFAULT 'TO_DO',
    "deadline" TIMESTAMP(3),
    "type" "AccountFinanceRequestType" NOT NULL,
    "archived" BOOLEAN NOT NULL DEFAULT false,
    "amount" DOUBLE PRECISION NOT NULL,
    "accountId" INTEGER,
    "userId" INTEGER NOT NULL
);

-- CreateTable
CREATE TABLE "account_manager_request" (
    "id" SERIAL NOT NULL,
    "createDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updateDate" TIMESTAMP(3) NOT NULL,
    "note" TEXT,
    "status" "GeneralRequestStatus" NOT NULL DEFAULT 'TO_DO',
    "deadline" TIMESTAMP(3),
    "type" "AccountManagerRequestType" NOT NULL,
    "archived" BOOLEAN NOT NULL DEFAULT false,
    "emailAccessAction" "EmailAccessAction",
    "accountFromId" INTEGER,
    "accountToId" INTEGER,
    "userId" INTEGER NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "account_finanace_request_id_key" ON "account_finanace_request"("id");

-- CreateIndex
CREATE UNIQUE INDEX "account_manager_request_id_key" ON "account_manager_request"("id");

-- AddForeignKey
ALTER TABLE "account_finanace_request" ADD CONSTRAINT "account_finanace_request_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "account"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "account_finanace_request" ADD CONSTRAINT "account_finanace_request_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "account_manager_request" ADD CONSTRAINT "account_manager_request_accountFromId_fkey" FOREIGN KEY ("accountFromId") REFERENCES "account"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "account_manager_request" ADD CONSTRAINT "account_manager_request_accountToId_fkey" FOREIGN KEY ("accountToId") REFERENCES "account"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "account_manager_request" ADD CONSTRAINT "account_manager_request_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
