-- CreateEnum
CREATE TYPE "MessageDirection" AS ENUM ('INBOUND', 'OUTBOUND');

-- CreateTable
CREATE TABLE "signal_messages" (
    "id" TEXT NOT NULL,
    "driverId" TEXT NOT NULL,
    "direction" "MessageDirection" NOT NULL,
    "content" TEXT NOT NULL,
    "timestamp" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "isRead" BOOLEAN NOT NULL DEFAULT false,
    "signalTimestamp" TEXT,

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

-- CreateIndex
CREATE INDEX "signal_messages_driverId_idx" ON "signal_messages"("driverId");

-- CreateIndex
CREATE INDEX "signal_messages_driverId_isRead_idx" ON "signal_messages"("driverId", "isRead");

-- CreateIndex
CREATE INDEX "signal_messages_timestamp_idx" ON "signal_messages"("timestamp");

-- AddForeignKey
ALTER TABLE "signal_messages" ADD CONSTRAINT "signal_messages_driverId_fkey" FOREIGN KEY ("driverId") REFERENCES "drivers"("id") ON DELETE CASCADE ON UPDATE CASCADE;
