-- CreateEnum
CREATE TYPE "GeneralRequestStatus" AS ENUM ('TO_DO', 'IN_PROGRESS', 'DONE');

-- CreateEnum
CREATE TYPE "TechRequestType" AS ENUM ('COST_TROUBLES', 'REVENUE_TROUBLES', 'NEW_BUYER_ACCESS');

-- CreateTable
CREATE TABLE "tech_request" (
    "id" SERIAL NOT NULL,
    "createDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updateDate" TIMESTAMP(3) NOT NULL,
    "trafficSource" "TrafficSource",
    "binomCampaignId" TEXT,
    "note" TEXT,
    "status" "GeneralRequestStatus" NOT NULL DEFAULT 'TO_DO',
    "dateFrom" TIMESTAMP(3),
    "dateTo" TIMESTAMP(3),
    "response" TEXT,
    "binomUserId" INTEGER,
    "teamId" INTEGER,
    "accountId" INTEGER,
    "userId" INTEGER NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "tech_request_id_key" ON "tech_request"("id");

-- AddForeignKey
ALTER TABLE "tech_request" ADD CONSTRAINT "tech_request_binomUserId_fkey" FOREIGN KEY ("binomUserId") REFERENCES "binom_user"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "tech_request" ADD CONSTRAINT "tech_request_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "team"("id") ON DELETE SET NULL ON UPDATE CASCADE;

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

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