-- CreateTable
CREATE TABLE `Property` (
    `id` VARCHAR(191) NOT NULL,
    `slug` VARCHAR(191) NOT NULL,
    `type` ENUM('villa', 'apartment', 'compound', 'commercial', 'office') NOT NULL,
    `status` ENUM('available', 'sold', 'reserved') NOT NULL,
    `titleAr` VARCHAR(191) NOT NULL,
    `titleEn` VARCHAR(191) NOT NULL,
    `priceSar` DECIMAL(14, 2) NOT NULL,
    `cityAr` VARCHAR(191) NOT NULL,
    `cityEn` VARCHAR(191) NOT NULL,
    `neighborhoodAr` VARCHAR(191) NULL,
    `neighborhoodEn` VARCHAR(191) NULL,
    `bedrooms` INTEGER NOT NULL,
    `bathrooms` INTEGER NOT NULL,
    `areaSqm` DECIMAL(12, 2) NOT NULL,
    `lat` DOUBLE NOT NULL,
    `lng` DOUBLE NOT NULL,
    `image` VARCHAR(2048) NOT NULL,
    `gallery` JSON NOT NULL,
    `isFeatured` BOOLEAN NOT NULL DEFAULT false,
    `maidRooms` INTEGER NULL,
    `parkingSpots` INTEGER NULL,
    `livingRooms` INTEGER NULL,
    `yearBuilt` INTEGER NULL,
    `utilities` JSON NULL,
    `acType` VARCHAR(191) NULL,
    `furnishing` VARCHAR(191) NULL,
    `descriptionAr` TEXT NULL,
    `descriptionEn` TEXT NULL,
    `publishedAt` DATETIME(3) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `Property_slug_key`(`slug`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `LandListing` (
    `id` VARCHAR(191) NOT NULL,
    `slug` VARCHAR(191) NOT NULL,
    `titleAr` VARCHAR(191) NOT NULL,
    `titleEn` VARCHAR(191) NOT NULL,
    `priceSar` DECIMAL(14, 2) NOT NULL,
    `areaSqm` DECIMAL(12, 2) NOT NULL,
    `zoningAr` VARCHAR(191) NOT NULL,
    `zoningEn` VARCHAR(191) NOT NULL,
    `cityAr` VARCHAR(191) NOT NULL,
    `cityEn` VARCHAR(191) NOT NULL,
    `lat` DOUBLE NOT NULL,
    `lng` DOUBLE NOT NULL,
    `image` VARCHAR(2048) NOT NULL,
    `isFeatured` BOOLEAN NOT NULL DEFAULT false,
    `streetWidthM` INTEGER NULL,
    `facadeCount` INTEGER NULL,
    `dimensionsAr` VARCHAR(191) NULL,
    `dimensionsEn` VARCHAR(191) NULL,
    `infrastructure` JSON NULL,
    `descriptionAr` TEXT NULL,
    `descriptionEn` TEXT NULL,
    `publishedAt` DATETIME(3) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `LandListing_slug_key`(`slug`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Project` (
    `id` VARCHAR(191) NOT NULL,
    `slug` VARCHAR(191) NOT NULL,
    `titleAr` VARCHAR(191) NOT NULL,
    `titleEn` VARCHAR(191) NOT NULL,
    `summaryAr` TEXT NOT NULL,
    `summaryEn` TEXT NOT NULL,
    `fromPriceSar` DECIMAL(14, 2) NOT NULL,
    `cityAr` VARCHAR(191) NOT NULL,
    `cityEn` VARCHAR(191) NOT NULL,
    `lat` DOUBLE NOT NULL,
    `lng` DOUBLE NOT NULL,
    `image` VARCHAR(2048) NOT NULL,
    `gallery` JSON NOT NULL,
    `isFeatured` BOOLEAN NOT NULL DEFAULT false,
    `publishedAt` DATETIME(3) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `Project_slug_key`(`slug`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `AmenityProximity` (
    `id` VARCHAR(191) NOT NULL,
    `propertyId` VARCHAR(191) NULL,
    `landId` VARCHAR(191) NULL,
    `projectId` VARCHAR(191) NULL,
    `labelAr` VARCHAR(191) NOT NULL,
    `labelEn` VARCHAR(191) NOT NULL,
    `category` VARCHAR(191) NOT NULL,
    `minutes` INTEGER NOT NULL,
    `mode` ENUM('driving', 'walking') NOT NULL DEFAULT 'driving',

    INDEX `AmenityProximity_propertyId_idx`(`propertyId`),
    INDEX `AmenityProximity_landId_idx`(`landId`),
    INDEX `AmenityProximity_projectId_idx`(`projectId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `HomepageProjectSlide` (
    `id` VARCHAR(191) NOT NULL,
    `projectId` VARCHAR(191) NOT NULL,
    `sortOrder` INTEGER NOT NULL DEFAULT 0,
    `titleAr` VARCHAR(191) NULL,
    `titleEn` VARCHAR(191) NULL,
    `subtitleAr` TEXT NULL,
    `subtitleEn` TEXT NULL,
    `image` VARCHAR(2048) NULL,
    `ctaAr` VARCHAR(191) NULL,
    `ctaEn` VARCHAR(191) NULL,
    `isActive` BOOLEAN NOT NULL DEFAULT true,

    INDEX `HomepageProjectSlide_sortOrder_idx`(`sortOrder`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `HomepageFeaturedPick` (
    `id` VARCHAR(191) NOT NULL,
    `kind` ENUM('property', 'land', 'project') NOT NULL,
    `sortOrder` INTEGER NOT NULL DEFAULT 0,
    `propertyId` VARCHAR(191) NULL,
    `landId` VARCHAR(191) NULL,
    `projectId` VARCHAR(191) NULL,

    INDEX `HomepageFeaturedPick_sortOrder_idx`(`sortOrder`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Partner` (
    `id` VARCHAR(191) NOT NULL,
    `nameAr` VARCHAR(191) NOT NULL,
    `nameEn` VARCHAR(191) NOT NULL,
    `url` VARCHAR(2048) NOT NULL,
    `logoUrl` VARCHAR(2048) NULL,
    `sortOrder` INTEGER NOT NULL DEFAULT 0,
    `isActive` BOOLEAN NOT NULL DEFAULT true,

    INDEX `Partner_sortOrder_idx`(`sortOrder`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `BlogPost` (
    `id` VARCHAR(191) NOT NULL,
    `slug` VARCHAR(191) NOT NULL,
    `titleAr` VARCHAR(191) NOT NULL,
    `titleEn` VARCHAR(191) NOT NULL,
    `excerptAr` TEXT NOT NULL,
    `excerptEn` TEXT NOT NULL,
    `contentAr` TEXT NULL,
    `contentEn` TEXT NULL,
    `publishedAt` DATETIME(3) NOT NULL,
    `cover` VARCHAR(2048) NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `BlogPost_slug_key`(`slug`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Lead` (
    `id` VARCHAR(191) NOT NULL,
    `name` VARCHAR(191) NOT NULL,
    `phone` VARCHAR(191) NOT NULL,
    `message` TEXT NULL,
    `source` VARCHAR(191) NOT NULL DEFAULT 'form',
    `propertySlug` VARCHAR(191) NULL,
    `landSlug` VARCHAR(191) NULL,
    `projectSlug` VARCHAR(191) NULL,
    `utmSource` VARCHAR(191) NULL,
    `utmMedium` VARCHAR(191) NULL,
    `utmCampaign` VARCHAR(191) NULL,
    `status` VARCHAR(191) NOT NULL DEFAULT 'new',
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    INDEX `Lead_createdAt_idx`(`createdAt`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `User` (
    `id` VARCHAR(191) NOT NULL,
    `email` VARCHAR(191) NOT NULL,
    `passwordHash` VARCHAR(191) NOT NULL,
    `role` ENUM('admin', 'editor', 'agent') NOT NULL DEFAULT 'editor',
    `isActive` BOOLEAN NOT NULL DEFAULT true,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `User_email_key`(`email`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `SiteSetting` (
    `key` VARCHAR(191) NOT NULL,
    `value` TEXT NOT NULL,

    PRIMARY KEY (`key`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `AmenityProximity` ADD CONSTRAINT `AmenityProximity_propertyId_fkey` FOREIGN KEY (`propertyId`) REFERENCES `Property`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `AmenityProximity` ADD CONSTRAINT `AmenityProximity_landId_fkey` FOREIGN KEY (`landId`) REFERENCES `LandListing`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `AmenityProximity` ADD CONSTRAINT `AmenityProximity_projectId_fkey` FOREIGN KEY (`projectId`) REFERENCES `Project`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `HomepageProjectSlide` ADD CONSTRAINT `HomepageProjectSlide_projectId_fkey` FOREIGN KEY (`projectId`) REFERENCES `Project`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `HomepageFeaturedPick` ADD CONSTRAINT `HomepageFeaturedPick_propertyId_fkey` FOREIGN KEY (`propertyId`) REFERENCES `Property`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `HomepageFeaturedPick` ADD CONSTRAINT `HomepageFeaturedPick_landId_fkey` FOREIGN KEY (`landId`) REFERENCES `LandListing`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `HomepageFeaturedPick` ADD CONSTRAINT `HomepageFeaturedPick_projectId_fkey` FOREIGN KEY (`projectId`) REFERENCES `Project`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
