-- CreateTable
CREATE TABLE "box" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "tags" TEXT[] DEFAULT ARRAY[]::TEXT[],
    "color" TEXT DEFAULT '#000000',
    "houseId" TEXT,
    "createrId" TEXT NOT NULL,
    "createdAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMPTZ NOT NULL,
    "deletedAt" TIMESTAMPTZ,
    "isPrivate" BOOLEAN NOT NULL DEFAULT false,

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

-- CreateTable
CREATE TABLE "item" (
    "id" TEXT NOT NULL,
    "createrId" TEXT NOT NULL,
    "boxId" TEXT,
    "image" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "price" TEXT,
    "tags" TEXT[] DEFAULT ARRAY[]::TEXT[],
    "quantity" INTEGER NOT NULL,
    "expiresAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "createdAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMPTZ NOT NULL,
    "deletedAt" TIMESTAMPTZ,

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

-- CreateIndex
CREATE INDEX "box_houseId_idx" ON "box"("houseId");

-- CreateIndex
CREATE INDEX "box_createrId_idx" ON "box"("createrId");

-- CreateIndex
CREATE INDEX "box_isPrivate_idx" ON "box"("isPrivate");

-- CreateIndex
CREATE INDEX "box_tags_idx" ON "box"("tags");

-- CreateIndex
CREATE INDEX "item_createrId_idx" ON "item"("createrId");

-- CreateIndex
CREATE INDEX "item_boxId_idx" ON "item"("boxId");

-- CreateIndex
CREATE INDEX "item_tags_idx" ON "item"("tags");

-- AddForeignKey
ALTER TABLE "box" ADD CONSTRAINT "box_houseId_fkey" FOREIGN KEY ("houseId") REFERENCES "house"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "box" ADD CONSTRAINT "box_createrId_fkey" FOREIGN KEY ("createrId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "item" ADD CONSTRAINT "item_createrId_fkey" FOREIGN KEY ("createrId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "item" ADD CONSTRAINT "item_boxId_fkey" FOREIGN KEY ("boxId") REFERENCES "box"("id") ON DELETE SET NULL ON UPDATE CASCADE;
