/*
  Warnings:

  - You are about to drop the `AuthToken` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `Monster` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `MonsterBiome` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `Player` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `ZoneBiomes` table. If the table is not empty, all the data it contains will be lost.

*/
-- CreateEnum
CREATE TYPE "biome" AS ENUM ('PLAINS', 'FIELDS', 'WOODLAND', 'FOREST', 'SWAMP', 'TUNDRA', 'MOUNTAIN', 'CAVE', 'DESERT');

-- CreateEnum
CREATE TYPE "monster_type" AS ENUM ('BEAST', 'FLYING', 'HUMANOID', 'GIANT', 'INSECT', 'UNDEAD');

-- DropForeignKey
ALTER TABLE "AuthToken" DROP CONSTRAINT "AuthToken_playerId_fkey";

-- DropForeignKey
ALTER TABLE "MonsterBiome" DROP CONSTRAINT "MonsterBiome_monsterId_fkey";

-- DropForeignKey
ALTER TABLE "Player" DROP CONSTRAINT "Player_zoneBiomeId_fkey";

-- DropTable
DROP TABLE "AuthToken";

-- DropTable
DROP TABLE "Monster";

-- DropTable
DROP TABLE "MonsterBiome";

-- DropTable
DROP TABLE "Player";

-- DropTable
DROP TABLE "ZoneBiomes";

-- DropEnum
DROP TYPE "Biome";

-- DropEnum
DROP TYPE "MonsterType";

-- CreateTable
CREATE TABLE "zone_biome" (
    "id" UUID NOT NULL,
    "playerId" UUID,
    "biome" "biome" NOT NULL,
    "maxSteps" INTEGER NOT NULL DEFAULT 500,

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

-- CreateTable
CREATE TABLE "player" (
    "id" UUID NOT NULL,
    "username" TEXT NOT NULL,
    "password" TEXT NOT NULL,
    "level" INTEGER NOT NULL DEFAULT 1,
    "currency" INTEGER NOT NULL DEFAULT 0,
    "pow" INTEGER NOT NULL,
    "zest" INTEGER NOT NULL,
    "woosh" INTEGER NOT NULL,
    "luck" INTEGER NOT NULL,
    "aha" INTEGER NOT NULL,
    "wow" INTEGER NOT NULL,
    "stamina" INTEGER NOT NULL,
    "hp" INTEGER NOT NULL,
    "statPoints" INTEGER NOT NULL DEFAULT 0,
    "exp" INTEGER NOT NULL DEFAULT 0,
    "zoneBiomeId" UUID NOT NULL,
    "steps" INTEGER NOT NULL DEFAULT 0,

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

-- CreateTable
CREATE TABLE "auth_token" (
    "token" UUID NOT NULL,
    "playerId" UUID NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3),

    CONSTRAINT "auth_token_pkey" PRIMARY KEY ("token")
);

-- CreateTable
CREATE TABLE "monster" (
    "id" UUID NOT NULL,
    "name" TEXT NOT NULL,
    "monsterType" "monster_type"[],

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

-- CreateTable
CREATE TABLE "monster_biome" (
    "monsterId" UUID NOT NULL,
    "biome" "biome" NOT NULL,
    "weight" DECIMAL(65,30) NOT NULL,
    "time" JSONB NOT NULL,

    CONSTRAINT "monster_biome_pkey" PRIMARY KEY ("monsterId","biome")
);

-- CreateIndex
CREATE UNIQUE INDEX "player_username_key" ON "player"("username");

-- CreateIndex
CREATE UNIQUE INDEX "player_zoneBiomeId_key" ON "player"("zoneBiomeId");

-- CreateIndex
CREATE UNIQUE INDEX "auth_token_playerId_key" ON "auth_token"("playerId");

-- CreateIndex
CREATE UNIQUE INDEX "monster_name_key" ON "monster"("name");

-- AddForeignKey
ALTER TABLE "player" ADD CONSTRAINT "player_zoneBiomeId_fkey" FOREIGN KEY ("zoneBiomeId") REFERENCES "zone_biome"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "auth_token" ADD CONSTRAINT "auth_token_playerId_fkey" FOREIGN KEY ("playerId") REFERENCES "player"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "monster_biome" ADD CONSTRAINT "monster_biome_monsterId_fkey" FOREIGN KEY ("monsterId") REFERENCES "monster"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
