-- CreateTable
CREATE TABLE "webhook_outbox" (
    "id" UUID NOT NULL,
    "job_id" UUID NOT NULL,
    "event" VARCHAR(80) NOT NULL,
    "payload" JSONB NOT NULL,
    "status" VARCHAR(20) NOT NULL DEFAULT 'pending',
    "attempts" INTEGER NOT NULL DEFAULT 0,
    "last_error" TEXT,
    "claimed_at" TIMESTAMP(3),
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "delivered_at" TIMESTAMP(3),

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

-- CreateIndex
CREATE UNIQUE INDEX "webhook_outbox_job_id_event_key" ON "webhook_outbox"("job_id", "event");

-- CreateIndex
CREATE INDEX "webhook_outbox_status_created_at_idx" ON "webhook_outbox"("status", "created_at");

-- AddForeignKey
ALTER TABLE "webhook_outbox" ADD CONSTRAINT "webhook_outbox_job_id_fkey" FOREIGN KEY ("job_id") REFERENCES "translation_jobs"("id") ON DELETE CASCADE ON UPDATE CASCADE;
