-- CreateTable
CREATE TABLE "Annotation" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "roomId" TEXT NOT NULL,
    "x" REAL NOT NULL DEFAULT 0,
    "y" REAL NOT NULL DEFAULT 0,
    "text" TEXT NOT NULL,
    "fontSize" INTEGER,
    "color" TEXT,
    "attachedToId" TEXT,
    "projectionOffsetX" REAL,
    "projectionOffsetY" REAL,
    CONSTRAINT "Annotation_roomId_fkey" FOREIGN KEY ("roomId") REFERENCES "Room" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_ElectricalItem" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "roomId" TEXT NOT NULL,
    "type" TEXT NOT NULL,
    "x" REAL NOT NULL,
    "y" REAL NOT NULL,
    "wallId" TEXT,
    "elevationFromFloor" REAL,
    "rotation" REAL NOT NULL DEFAULT 0,
    "count" INTEGER NOT NULL DEFAULT 1,
    "anchorH" TEXT NOT NULL DEFAULT 'middle',
    "anchorV" TEXT NOT NULL DEFAULT 'middle',
    "metadata" TEXT,
    CONSTRAINT "ElectricalItem_roomId_fkey" FOREIGN KEY ("roomId") REFERENCES "Room" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_ElectricalItem" ("elevationFromFloor", "id", "metadata", "roomId", "rotation", "type", "wallId", "x", "y") SELECT "elevationFromFloor", "id", "metadata", "roomId", "rotation", "type", "wallId", "x", "y" FROM "ElectricalItem";
DROP TABLE "ElectricalItem";
ALTER TABLE "new_ElectricalItem" RENAME TO "ElectricalItem";
CREATE INDEX "ElectricalItem_roomId_idx" ON "ElectricalItem"("roomId");
CREATE TABLE "new_FurnitureItem" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "roomId" TEXT NOT NULL,
    "type" TEXT NOT NULL,
    "x" REAL NOT NULL,
    "y" REAL NOT NULL,
    "width" REAL NOT NULL,
    "depth" REAL NOT NULL,
    "height" REAL NOT NULL,
    "rotation" REAL NOT NULL DEFAULT 0,
    "elevationFromFloor" REAL NOT NULL DEFAULT 0,
    "label" TEXT,
    "anchorH" TEXT NOT NULL DEFAULT 'middle',
    "anchorV" TEXT NOT NULL DEFAULT 'middle',
    "showProjection" BOOLEAN NOT NULL DEFAULT false,
    "opacity" REAL NOT NULL DEFAULT 1,
    CONSTRAINT "FurnitureItem_roomId_fkey" FOREIGN KEY ("roomId") REFERENCES "Room" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_FurnitureItem" ("depth", "height", "id", "label", "roomId", "rotation", "type", "width", "x", "y") SELECT "depth", "height", "id", "label", "roomId", "rotation", "type", "width", "x", "y" FROM "FurnitureItem";
DROP TABLE "FurnitureItem";
ALTER TABLE "new_FurnitureItem" RENAME TO "FurnitureItem";
CREATE INDEX "FurnitureItem_roomId_idx" ON "FurnitureItem"("roomId");
CREATE TABLE "new_Room" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "apartmentId" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "shape" TEXT NOT NULL DEFAULT '[]',
    "width" REAL,
    "height" REAL,
    "wallHeight" REAL NOT NULL DEFAULT 2.7,
    "plinthHeight" REAL NOT NULL DEFAULT 0.06,
    "plinthThickness" REAL NOT NULL DEFAULT 0.01,
    "order" INTEGER NOT NULL DEFAULT 0,
    "posX" REAL NOT NULL DEFAULT 0,
    "posY" REAL NOT NULL DEFAULT 0,
    "floorType" TEXT NOT NULL DEFAULT 'CONCRETE',
    "wallColor" TEXT NOT NULL DEFAULT '#f5f0eb',
    "outletWidth" REAL NOT NULL DEFAULT 0.07,
    "outletHeight" REAL NOT NULL DEFAULT 0.07,
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" DATETIME NOT NULL,
    CONSTRAINT "Room_apartmentId_fkey" FOREIGN KEY ("apartmentId") REFERENCES "Apartment" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_Room" ("apartmentId", "createdAt", "height", "id", "name", "order", "plinthHeight", "plinthThickness", "posX", "posY", "shape", "updatedAt", "wallHeight", "width") SELECT "apartmentId", "createdAt", "height", "id", "name", "order", "plinthHeight", "plinthThickness", "posX", "posY", "shape", "updatedAt", "wallHeight", "width" FROM "Room";
DROP TABLE "Room";
ALTER TABLE "new_Room" RENAME TO "Room";
CREATE INDEX "Room_apartmentId_idx" ON "Room"("apartmentId");
CREATE TABLE "new_WallOpening" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "roomId" TEXT NOT NULL,
    "wallId" TEXT NOT NULL,
    "type" TEXT NOT NULL,
    "positionAlongWall" REAL NOT NULL,
    "width" REAL NOT NULL,
    "height" REAL NOT NULL,
    "elevationFromFloor" REAL NOT NULL DEFAULT 0,
    "openDirection" TEXT NOT NULL DEFAULT 'LEFT',
    "anchorH" TEXT NOT NULL DEFAULT 'middle',
    "anchorV" TEXT NOT NULL DEFAULT 'middle',
    CONSTRAINT "WallOpening_roomId_fkey" FOREIGN KEY ("roomId") REFERENCES "Room" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "WallOpening_wallId_fkey" FOREIGN KEY ("wallId") REFERENCES "Wall" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_WallOpening" ("elevationFromFloor", "height", "id", "positionAlongWall", "roomId", "type", "wallId", "width") SELECT "elevationFromFloor", "height", "id", "positionAlongWall", "roomId", "type", "wallId", "width" FROM "WallOpening";
DROP TABLE "WallOpening";
ALTER TABLE "new_WallOpening" RENAME TO "WallOpening";
CREATE INDEX "WallOpening_roomId_idx" ON "WallOpening"("roomId");
CREATE INDEX "WallOpening_wallId_idx" ON "WallOpening"("wallId");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;

-- CreateIndex
CREATE INDEX "Annotation_roomId_idx" ON "Annotation"("roomId");
