-- AlterTable
ALTER TABLE "Inbox" ADD COLUMN "lastSpamRescuedAt" DATETIME;
ALTER TABLE "Inbox" ADD COLUMN "spamFolderPath" TEXT;

-- CreateTable
CREATE TABLE "SendJob" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "campaignId" TEXT NOT NULL,
    "scheduledAt" DATETIME NOT NULL,
    "status" TEXT NOT NULL DEFAULT 'pending',
    "idempotencyKey" TEXT NOT NULL,
    "processedAt" DATETIME,
    "errorMessage" TEXT,
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" DATETIME NOT NULL,
    CONSTRAINT "SendJob_campaignId_fkey" FOREIGN KEY ("campaignId") REFERENCES "WarmupCampaign" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "JobRunLog" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "jobName" TEXT NOT NULL,
    "ranAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "success" BOOLEAN NOT NULL DEFAULT true,
    "message" TEXT
);

-- CreateIndex
CREATE UNIQUE INDEX "SendJob_idempotencyKey_key" ON "SendJob"("idempotencyKey");

-- CreateIndex
CREATE INDEX "SendJob_campaignId_status_scheduledAt_idx" ON "SendJob"("campaignId", "status", "scheduledAt");

-- CreateIndex
CREATE INDEX "JobRunLog_jobName_ranAt_idx" ON "JobRunLog"("jobName", "ranAt");
