/*
  Warnings:

  - Added the required column `topUpRequestId` to the `top_up` table without a default value. This is not possible if the table is not empty.

*/
-- CreateEnum
CREATE TYPE "RequestType" AS ENUM ('ACCOUNT_REQUEST', 'TECH_REQUEST', 'SHARE_REQUEST', 'RENAME_REQUEST');

-- CreateEnum
CREATE TYPE "Vertical" AS ENUM ('EDUCATION', 'EMPLOYMENT', 'HEALTH_BEAUTY', 'SWEEPSTAKES', 'INSURANCE', 'FINANCE', 'DATING', 'HOME_SERVICES', 'GAMING', 'SOCIAL_CASINO', 'ECOMMERCE', 'SEARCH', 'OTHER');

-- CreateEnum
CREATE TYPE "RequestStatus" AS ENUM ('NEW', 'IN_PROGRESS_BY_AGENCY', 'IN_PROGRESS', 'ERROR', 'DONE');

-- CreateEnum
CREATE TYPE "TopUpRequestStatus" AS ENUM ('NEW', 'IN_PROGRESS_BY_AGENCY', 'IN_PROGRESS', 'ERROR', 'DONE');

-- AlterEnum
-- This migration adds more than one value to an enum.
-- With PostgreSQL versions 11 and earlier, this is not possible
-- in a single migration. This can be worked around by creating
-- multiple migrations, each migration adding only one value to
-- the enum.


ALTER TYPE "TrafficSource" ADD VALUE 'GOOGLE';
ALTER TYPE "TrafficSource" ADD VALUE 'BIGO';
ALTER TYPE "TrafficSource" ADD VALUE 'BING';

-- AlterTable
ALTER TABLE "account" ADD COLUMN     "accountRequestId" INTEGER;

-- AlterTable
ALTER TABLE "top_up" ADD COLUMN     "topUpRequestId" INTEGER NOT NULL;

-- DropEnum
DROP TYPE "AccountFinanceRequestType";

-- CreateTable
CREATE TABLE "top_up_request" (
    "id" SERIAL NOT NULL,
    "createDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updateDate" TIMESTAMP(3) NOT NULL,
    "note" TEXT,
    "status" "TopUpRequestStatus" NOT NULL DEFAULT 'NEW',
    "deadline" TIMESTAMP(3),
    "archived" BOOLEAN NOT NULL DEFAULT false,
    "userId" INTEGER NOT NULL
);

-- CreateTable
CREATE TABLE "account_request" (
    "id" SERIAL NOT NULL,
    "createDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updateDate" TIMESTAMP(3) NOT NULL,
    "amount" INTEGER NOT NULL,
    "vertical" "Vertical" NOT NULL,
    "whitelist" BOOLEAN NOT NULL,
    "facebookPage" TEXT NOT NULL,
    "shareAccessEmail" TEXT NOT NULL,
    "comment" TEXT NOT NULL,
    "tfType" "TrafficSource" NOT NULL,
    "requestType" "RequestType" NOT NULL DEFAULT 'ACCOUNT_REQUEST',
    "status" "RequestStatus" NOT NULL,
    "accessProvidedConfirm" BOOLEAN NOT NULL,
    "timezoneId" INTEGER NOT NULL,

    CONSTRAINT "account_request_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "account_request_website" (
    "id" SERIAL NOT NULL,
    "createDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updateDate" TIMESTAMP(3) NOT NULL,
    "url" TEXT NOT NULL,
    "geo" TEXT NOT NULL,
    "accountRequestId" INTEGER NOT NULL,

    CONSTRAINT "account_request_website_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "top_up_request_id_key" ON "top_up_request"("id");

-- AddForeignKey
ALTER TABLE "account" ADD CONSTRAINT "account_accountRequestId_fkey" FOREIGN KEY ("accountRequestId") REFERENCES "account_request"("id") ON DELETE SET NULL ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE "top_up" ADD CONSTRAINT "top_up_topUpRequestId_fkey" FOREIGN KEY ("topUpRequestId") REFERENCES "top_up_request"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "account_request" ADD CONSTRAINT "account_request_timezoneId_fkey" FOREIGN KEY ("timezoneId") REFERENCES "timezone"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "account_request_website" ADD CONSTRAINT "account_request_website_accountRequestId_fkey" FOREIGN KEY ("accountRequestId") REFERENCES "account_request"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
