-- CreateEnum
CREATE TYPE "ResearchField" AS ENUM ('BOMBER', 'CHIRURGEON', 'MUTAGENIST', 'TOXICOLOGIST');

-- CreateTable
CREATE TABLE "CharacterAlchemyState" (
    "id" TEXT NOT NULL,
    "characterId" TEXT NOT NULL,
    "researchField" "ResearchField",
    "versatileVialsCurrent" INTEGER NOT NULL DEFAULT 0,
    "versatileVialsMax" INTEGER NOT NULL DEFAULT 0,
    "advancedAlchemyBatch" INTEGER NOT NULL DEFAULT 0,
    "advancedAlchemyMax" INTEGER NOT NULL DEFAULT 0,
    "lastRestAt" TIMESTAMP(3),

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

-- CreateTable
CREATE TABLE "CharacterFormula" (
    "id" TEXT NOT NULL,
    "characterId" TEXT NOT NULL,
    "equipmentId" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "nameGerman" TEXT,
    "learnedAt" INTEGER NOT NULL DEFAULT 1,
    "formulaSource" TEXT,

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

-- CreateTable
CREATE TABLE "CharacterPreparedItem" (
    "id" TEXT NOT NULL,
    "characterId" TEXT NOT NULL,
    "equipmentId" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "nameGerman" TEXT,
    "quantity" INTEGER NOT NULL DEFAULT 1,
    "isQuickAlchemy" BOOLEAN NOT NULL DEFAULT false,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE UNIQUE INDEX "CharacterAlchemyState_characterId_key" ON "CharacterAlchemyState"("characterId");

-- CreateIndex
CREATE INDEX "CharacterFormula_characterId_idx" ON "CharacterFormula"("characterId");

-- CreateIndex
CREATE UNIQUE INDEX "CharacterFormula_characterId_equipmentId_key" ON "CharacterFormula"("characterId", "equipmentId");

-- CreateIndex
CREATE INDEX "CharacterPreparedItem_characterId_idx" ON "CharacterPreparedItem"("characterId");

-- AddForeignKey
ALTER TABLE "CharacterAlchemyState" ADD CONSTRAINT "CharacterAlchemyState_characterId_fkey" FOREIGN KEY ("characterId") REFERENCES "Character"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CharacterFormula" ADD CONSTRAINT "CharacterFormula_characterId_fkey" FOREIGN KEY ("characterId") REFERENCES "Character"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CharacterFormula" ADD CONSTRAINT "CharacterFormula_equipmentId_fkey" FOREIGN KEY ("equipmentId") REFERENCES "Equipment"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CharacterPreparedItem" ADD CONSTRAINT "CharacterPreparedItem_characterId_fkey" FOREIGN KEY ("characterId") REFERENCES "Character"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CharacterPreparedItem" ADD CONSTRAINT "CharacterPreparedItem_equipmentId_fkey" FOREIGN KEY ("equipmentId") REFERENCES "Equipment"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
