-- CreateTable
CREATE TABLE "RouteSegment" (
    "id" TEXT NOT NULL,
    "tripId" TEXT NOT NULL,
    "fromDestId" TEXT NOT NULL,
    "toDestId" TEXT NOT NULL,
    "profile" TEXT NOT NULL DEFAULT 'driving-car',
    "distanceMeters" INTEGER,
    "durationSeconds" INTEGER,
    "geometry" TEXT,
    "computedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE INDEX "RouteSegment_tripId_idx" ON "RouteSegment"("tripId");

-- CreateIndex
CREATE UNIQUE INDEX "RouteSegment_tripId_fromDestId_toDestId_profile_key" ON "RouteSegment"("tripId", "fromDestId", "toDestId", "profile");

-- AddForeignKey
ALTER TABLE "RouteSegment" ADD CONSTRAINT "RouteSegment_tripId_fkey" FOREIGN KEY ("tripId") REFERENCES "Trip"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "RouteSegment" ADD CONSTRAINT "RouteSegment_fromDestId_fkey" FOREIGN KEY ("fromDestId") REFERENCES "Destination"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "RouteSegment" ADD CONSTRAINT "RouteSegment_toDestId_fkey" FOREIGN KEY ("toDestId") REFERENCES "Destination"("id") ON DELETE CASCADE ON UPDATE CASCADE;
