-- CreateTable
CREATE TABLE `dealer_leads` (
    `id` VARCHAR(191) NOT NULL,
    `listing_id` VARCHAR(191) NOT NULL,
    `user_id` VARCHAR(191) NOT NULL,
    `dealer_user_id` VARCHAR(191) NOT NULL,
    `source` ENUM('WISHLIST', 'TEST_DRIVE', 'CONTACT_SELLER') NOT NULL,
    `status` ENUM('NEW', 'CONTACTED', 'CONVERTED', 'CLOSED', 'LOST') NOT NULL DEFAULT 'NEW',
    `message` TEXT NULL,
    `meeting_at` DATETIME(3) NULL,
    `customer_name` VARCHAR(120) NOT NULL,
    `customer_phone` VARCHAR(15) NULL,
    `customer_email` VARCHAR(120) NOT NULL,
    `customer_city` VARCHAR(80) NULL,
    `customer_state` VARCHAR(80) NULL,
    `customer_image_url` VARCHAR(500) NULL,
    `car_title` VARCHAR(200) NOT NULL,
    `car_price` DECIMAL(12, 2) NOT NULL,
    `car_year` INTEGER NOT NULL,
    `car_fuel_type` VARCHAR(80) NULL,
    `car_transmission` VARCHAR(80) NULL,
    `car_registration` VARCHAR(20) NULL,
    `car_image_url` VARCHAR(500) NULL,
    `car_location` VARCHAR(200) NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,

    UNIQUE INDEX `dealer_leads_listing_id_user_id_key`(`listing_id`, `user_id`),
    INDEX `dealer_leads_dealer_user_id_created_at_idx`(`dealer_user_id`, `created_at`),
    INDEX `dealer_leads_dealer_user_id_status_idx`(`dealer_user_id`, `status`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `super_admin_leads` (
    `id` VARCHAR(191) NOT NULL,
    `listing_id` VARCHAR(191) NOT NULL,
    `user_id` VARCHAR(191) NOT NULL,
    `seller_user_id` VARCHAR(191) NOT NULL,
    `seller_type` ENUM('INDIVIDUAL', 'DEALER') NOT NULL,
    `seller_name` VARCHAR(120) NOT NULL,
    `source` ENUM('WISHLIST', 'TEST_DRIVE', 'CONTACT_SELLER') NOT NULL,
    `status` ENUM('NEW', 'CONTACTED', 'CONVERTED', 'CLOSED', 'LOST') NOT NULL DEFAULT 'NEW',
    `message` TEXT NULL,
    `meeting_at` DATETIME(3) NULL,
    `customer_name` VARCHAR(120) NOT NULL,
    `customer_phone` VARCHAR(15) NULL,
    `customer_email` VARCHAR(120) NOT NULL,
    `customer_city` VARCHAR(80) NULL,
    `customer_state` VARCHAR(80) NULL,
    `customer_image_url` VARCHAR(500) NULL,
    `car_title` VARCHAR(200) NOT NULL,
    `car_price` DECIMAL(12, 2) NOT NULL,
    `car_year` INTEGER NOT NULL,
    `car_fuel_type` VARCHAR(80) NULL,
    `car_transmission` VARCHAR(80) NULL,
    `car_registration` VARCHAR(20) NULL,
    `car_image_url` VARCHAR(500) NULL,
    `car_location` VARCHAR(200) NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,

    UNIQUE INDEX `super_admin_leads_listing_id_user_id_key`(`listing_id`, `user_id`),
    INDEX `super_admin_leads_seller_user_id_created_at_idx`(`seller_user_id`, `created_at`),
    INDEX `super_admin_leads_status_created_at_idx`(`status`, `created_at`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `dealer_leads` ADD CONSTRAINT `dealer_leads_listing_id_fkey` FOREIGN KEY (`listing_id`) REFERENCES `car_listings`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `dealer_leads` ADD CONSTRAINT `dealer_leads_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `dealer_leads` ADD CONSTRAINT `dealer_leads_dealer_user_id_fkey` FOREIGN KEY (`dealer_user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `super_admin_leads` ADD CONSTRAINT `super_admin_leads_listing_id_fkey` FOREIGN KEY (`listing_id`) REFERENCES `car_listings`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `super_admin_leads` ADD CONSTRAINT `super_admin_leads_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
