-- CreateTable
CREATE TABLE "SegmentFareRule" (
    "id" TEXT NOT NULL,
    "routeId" TEXT NOT NULL,
    "originStopSequence" INTEGER NOT NULL,
    "destinationStopSequence" INTEGER NOT NULL,
    "seatClassId" TEXT NOT NULL,
    "baseFareMinor" INTEGER NOT NULL,
    "nationality" TEXT,
    "currency" TEXT NOT NULL DEFAULT 'ETB',
    "validFrom" TIMESTAMP(3) NOT NULL,
    "validUntil" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE INDEX "SegmentFareRule_routeId_seatClassId_idx" ON "SegmentFareRule"("routeId", "seatClassId");

-- CreateIndex
CREATE UNIQUE INDEX "SegmentFareRule_routeId_originStopSequence_destinationStopS_key" ON "SegmentFareRule"("routeId", "originStopSequence", "destinationStopSequence", "seatClassId", "nationality");

-- AddForeignKey
ALTER TABLE "SegmentFareRule" ADD CONSTRAINT "SegmentFareRule_routeId_fkey" FOREIGN KEY ("routeId") REFERENCES "Route"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "SegmentFareRule" ADD CONSTRAINT "SegmentFareRule_seatClassId_fkey" FOREIGN KEY ("seatClassId") REFERENCES "SeatClass"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
