-- CreateEnum
CREATE TYPE "PrazoStatus" AS ENUM ('PENDENTE', 'CONCLUIDO', 'VENCIDO', 'CANCELADO');

-- CreateEnum
CREATE TYPE "PrazoPriority" AS ENUM ('ALTA', 'MEDIA', 'BAIXA');

-- CreateEnum
CREATE TYPE "AuditStatus" AS ENUM ('PENDING', 'ANALYZING', 'DONE', 'ERROR');

-- CreateTable
CREATE TABLE "Prazo" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "title" TEXT NOT NULL,
    "description" TEXT,
    "processNumber" TEXT,
    "court" TEXT,
    "deadline" TIMESTAMP(3) NOT NULL,
    "alertDays" INTEGER NOT NULL DEFAULT 3,
    "status" "PrazoStatus" NOT NULL DEFAULT 'PENDENTE',
    "priority" "PrazoPriority" NOT NULL DEFAULT 'MEDIA',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "ContractAudit" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "title" TEXT NOT NULL,
    "content" TEXT NOT NULL,
    "analysis" JSONB,
    "status" "AuditStatus" NOT NULL DEFAULT 'PENDING',
    "riskScore" INTEGER,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- AddForeignKey
ALTER TABLE "Prazo" ADD CONSTRAINT "Prazo_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ContractAudit" ADD CONSTRAINT "ContractAudit_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
