-- CreateTable
CREATE TABLE `test_drive_requests` (
    `id` VARCHAR(191) NOT NULL,
    `listing_id` VARCHAR(191) NOT NULL,
    `requester_id` VARCHAR(191) NOT NULL,
    `requester_name` VARCHAR(120) NOT NULL,
    `requester_phone` VARCHAR(15) NOT NULL,
    `requester_email` VARCHAR(120) NOT NULL,
    `preferred_date` DATE NOT NULL,
    `preferred_time` VARCHAR(8) NOT NULL,
    `status` ENUM('PENDING', 'ACCEPTED', 'REJECTED', 'CANCELLED', 'COMPLETED') NOT NULL DEFAULT 'PENDING',
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,

    INDEX `test_drive_requests_listing_id_requester_id_status_idx`(`listing_id`, `requester_id`, `status`),
    INDEX `test_drive_requests_requester_id_created_at_idx`(`requester_id`, `created_at`),
    INDEX `test_drive_requests_listing_id_created_at_idx`(`listing_id`, `created_at`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

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

-- AddForeignKey
ALTER TABLE `test_drive_requests` ADD CONSTRAINT `test_drive_requests_requester_id_fkey` FOREIGN KEY (`requester_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
