-- CreateTable
CREATE TABLE "Category" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "slug" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "nameEs" TEXT,
    "nameFr" TEXT,
    "kind" TEXT NOT NULL,
    "parentId" TEXT,
    "sortOrder" INTEGER NOT NULL DEFAULT 0,
    "active" BOOLEAN NOT NULL DEFAULT true,
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" DATETIME NOT NULL,
    CONSTRAINT "Category_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "Category" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);

-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Listing" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "slug" TEXT NOT NULL,
    "title" TEXT NOT NULL,
    "titleEs" TEXT,
    "titleFr" TEXT,
    "description" TEXT NOT NULL,
    "descriptionEs" TEXT,
    "descriptionFr" TEXT,
    "priceUsd" DECIMAL,
    "type" TEXT NOT NULL,
    "beds" INTEGER,
    "baths" DECIMAL,
    "sqft" INTEGER,
    "address" TEXT,
    "areaKey" TEXT,
    "categoryId" TEXT,
    "mls" TEXT,
    "youtubeId" TEXT,
    "status" TEXT NOT NULL DEFAULT 'DRAFT',
    "agentId" TEXT NOT NULL,
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" DATETIME NOT NULL,
    "publishedAt" DATETIME,
    CONSTRAINT "Listing_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "Category" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
    CONSTRAINT "Listing_agentId_fkey" FOREIGN KEY ("agentId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_Listing" ("address", "agentId", "areaKey", "baths", "beds", "createdAt", "description", "descriptionEs", "descriptionFr", "id", "mls", "priceUsd", "publishedAt", "slug", "sqft", "status", "title", "titleEs", "titleFr", "type", "updatedAt", "youtubeId") SELECT "address", "agentId", "areaKey", "baths", "beds", "createdAt", "description", "descriptionEs", "descriptionFr", "id", "mls", "priceUsd", "publishedAt", "slug", "sqft", "status", "title", "titleEs", "titleFr", "type", "updatedAt", "youtubeId" FROM "Listing";
DROP TABLE "Listing";
ALTER TABLE "new_Listing" RENAME TO "Listing";
CREATE UNIQUE INDEX "Listing_slug_key" ON "Listing"("slug");
CREATE INDEX "Listing_status_publishedAt_idx" ON "Listing"("status", "publishedAt");
CREATE INDEX "Listing_agentId_idx" ON "Listing"("agentId");
CREATE INDEX "Listing_slug_idx" ON "Listing"("slug");
CREATE TABLE "new_Rental" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "slug" TEXT NOT NULL,
    "hostId" TEXT NOT NULL,
    "title" TEXT NOT NULL,
    "titleEs" TEXT,
    "titleFr" TEXT,
    "description" TEXT NOT NULL,
    "descriptionEs" TEXT,
    "descriptionFr" TEXT,
    "nightlyRate" DECIMAL NOT NULL,
    "cleaningFee" DECIMAL,
    "currency" TEXT NOT NULL DEFAULT 'USD',
    "minNights" INTEGER NOT NULL DEFAULT 1,
    "address" TEXT,
    "areaKey" TEXT,
    "latitude" REAL,
    "longitude" REAL,
    "bedrooms" INTEGER,
    "bathrooms" DECIMAL,
    "guests" INTEGER,
    "categoryId" TEXT,
    "amenities" TEXT NOT NULL DEFAULT '[]',
    "airbnbUrl" TEXT,
    "vrboUrl" TEXT,
    "websiteUrl" TEXT,
    "icalUrl" TEXT,
    "icalLastSyncedAt" DATETIME,
    "icalSyncStatus" TEXT,
    "status" TEXT NOT NULL DEFAULT 'PUBLISHED',
    "isFeatured" BOOLEAN NOT NULL DEFAULT false,
    "publishedAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" DATETIME NOT NULL,
    CONSTRAINT "Rental_hostId_fkey" FOREIGN KEY ("hostId") REFERENCES "Host" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "Rental_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "Category" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);
INSERT INTO "new_Rental" ("address", "airbnbUrl", "amenities", "areaKey", "bathrooms", "bedrooms", "cleaningFee", "createdAt", "currency", "description", "descriptionEs", "descriptionFr", "guests", "hostId", "icalLastSyncedAt", "icalSyncStatus", "icalUrl", "id", "isFeatured", "latitude", "longitude", "minNights", "nightlyRate", "publishedAt", "slug", "status", "title", "titleEs", "titleFr", "updatedAt", "vrboUrl", "websiteUrl") SELECT "address", "airbnbUrl", "amenities", "areaKey", "bathrooms", "bedrooms", "cleaningFee", "createdAt", "currency", "description", "descriptionEs", "descriptionFr", "guests", "hostId", "icalLastSyncedAt", "icalSyncStatus", "icalUrl", "id", "isFeatured", "latitude", "longitude", "minNights", "nightlyRate", "publishedAt", "slug", "status", "title", "titleEs", "titleFr", "updatedAt", "vrboUrl", "websiteUrl" FROM "Rental";
DROP TABLE "Rental";
ALTER TABLE "new_Rental" RENAME TO "Rental";
CREATE UNIQUE INDEX "Rental_slug_key" ON "Rental"("slug");
CREATE INDEX "Rental_status_publishedAt_idx" ON "Rental"("status", "publishedAt");
CREATE INDEX "Rental_hostId_idx" ON "Rental"("hostId");
CREATE INDEX "Rental_areaKey_idx" ON "Rental"("areaKey");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;

-- CreateIndex
CREATE UNIQUE INDEX "Category_slug_key" ON "Category"("slug");

-- CreateIndex
CREATE INDEX "Category_kind_active_idx" ON "Category"("kind", "active");

-- CreateIndex
CREATE INDEX "Category_parentId_idx" ON "Category"("parentId");

