-- CreateTable
CREATE TABLE "elo_ratings" (
    "id" SERIAL NOT NULL,
    "playerId" INTEGER NOT NULL,
    "rating" INTEGER NOT NULL DEFAULT 1000,
    "volatility" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "gamesPlayed" INTEGER NOT NULL DEFAULT 0,
    "wins" INTEGER NOT NULL DEFAULT 0,
    "losses" INTEGER NOT NULL DEFAULT 0,
    "draws" INTEGER NOT NULL DEFAULT 0,
    "lastUpdated" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "glicko2_ratings" (
    "id" SERIAL NOT NULL,
    "playerId" INTEGER NOT NULL,
    "rating" DOUBLE PRECISION NOT NULL DEFAULT 1500.0,
    "deviation" DOUBLE PRECISION NOT NULL DEFAULT 350.0,
    "volatility" DOUBLE PRECISION NOT NULL DEFAULT 0.05,
    "gamesPlayed" INTEGER NOT NULL DEFAULT 0,
    "wins" INTEGER NOT NULL DEFAULT 0,
    "losses" INTEGER NOT NULL DEFAULT 0,
    "draws" INTEGER NOT NULL DEFAULT 0,
    "lastUpdated" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "open_skill_ratings" (
    "id" SERIAL NOT NULL,
    "playerId" INTEGER NOT NULL,
    "rating" DOUBLE PRECISION NOT NULL DEFAULT 25.0,
    "deviation" DOUBLE PRECISION NOT NULL DEFAULT 8.33,
    "gamesPlayed" INTEGER NOT NULL DEFAULT 0,
    "wins" INTEGER NOT NULL DEFAULT 0,
    "losses" INTEGER NOT NULL DEFAULT 0,
    "draws" INTEGER NOT NULL DEFAULT 0,
    "lastUpdated" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "elo_ratings_playerId_key" ON "elo_ratings"("playerId");

-- CreateIndex
CREATE UNIQUE INDEX "glicko2_ratings_playerId_key" ON "glicko2_ratings"("playerId");

-- CreateIndex
CREATE UNIQUE INDEX "open_skill_ratings_playerId_key" ON "open_skill_ratings"("playerId");

-- AddForeignKey
ALTER TABLE "elo_ratings" ADD CONSTRAINT "elo_ratings_playerId_fkey" FOREIGN KEY ("playerId") REFERENCES "players"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "glicko2_ratings" ADD CONSTRAINT "glicko2_ratings_playerId_fkey" FOREIGN KEY ("playerId") REFERENCES "players"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "open_skill_ratings" ADD CONSTRAINT "open_skill_ratings_playerId_fkey" FOREIGN KEY ("playerId") REFERENCES "players"("id") ON DELETE CASCADE ON UPDATE CASCADE;
