-- CreateTable
CREATE TABLE `moderation_reports` (
    `id` VARCHAR(191) NOT NULL,
    `report_number` VARCHAR(20) NOT NULL,
    `reporter_user_id` VARCHAR(191) NOT NULL,
    `report_type` ENUM('LISTING', 'SELLER') NOT NULL,
    `listing_id` VARCHAR(191) NOT NULL,
    `seller_user_id` VARCHAR(191) NOT NULL,
    `description` VARCHAR(2000) NOT NULL,
    `status` ENUM('PENDING', 'UNDER_REVIEW', 'RESOLVED', 'REJECTED') NOT NULL DEFAULT 'PENDING',
    `action_taken` ENUM('NONE', 'LISTING_REJECTED', 'SELLER_BLOCKED', 'REPORT_DISMISSED') NULL,
    `admin_note` VARCHAR(500) NULL,
    `reporter_name` VARCHAR(120) NOT NULL,
    `reporter_phone` VARCHAR(15) NULL,
    `reporter_email` VARCHAR(120) NOT NULL,
    `item_title` VARCHAR(200) NOT NULL,
    `item_meta` VARCHAR(120) NULL,
    `item_image_url` VARCHAR(500) NULL,
    `seller_name` VARCHAR(120) NOT NULL,
    `seller_phone` VARCHAR(15) NULL,
    `seller_type` ENUM('INDIVIDUAL', 'DEALER') NOT NULL,
    `updated_by_user_id` VARCHAR(191) NULL,
    `updated_by_name` VARCHAR(120) NULL,
    `updated_by_role` ENUM('USER', 'DEALER', 'EMPLOYEE', 'SUPERADMIN') NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,

    UNIQUE INDEX `moderation_reports_report_number_key`(`report_number`),
    INDEX `moderation_reports_reporter_user_id_created_at_idx`(`reporter_user_id`, `created_at`),
    INDEX `moderation_reports_listing_id_created_at_idx`(`listing_id`, `created_at`),
    INDEX `moderation_reports_seller_user_id_created_at_idx`(`seller_user_id`, `created_at`),
    INDEX `moderation_reports_status_created_at_idx`(`status`, `created_at`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `moderation_reports` ADD CONSTRAINT `moderation_reports_reporter_user_id_fkey` FOREIGN KEY (`reporter_user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE `moderation_reports` ADD CONSTRAINT `moderation_reports_seller_user_id_fkey` FOREIGN KEY (`seller_user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
