-- 查价查询审计（最多保留 1000 条，应用层裁剪）
CREATE TABLE `quote_query_log` (
    `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    `quote_id` VARCHAR(32) NOT NULL,
    `request_id` VARCHAR(36) NOT NULL,
    `customer_id` VARCHAR(32) NOT NULL,
    `pickup_json` JSON NOT NULL,
    `delivery_json` JSON NOT NULL,
    `cargo_json` JSON NOT NULL,
    `outcome` VARCHAR(16) NOT NULL DEFAULT 'processing',
    `failure_reason` VARCHAR(512) NULL,
    `error_code` VARCHAR(32) NULL,
    `source_type` VARCHAR(16) NULL,
    `tier_count` INTEGER NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `completed_at` DATETIME(3) NULL,

    UNIQUE INDEX `quote_query_log_quote_id_key`(`quote_id`),
    INDEX `idx_query_log_created`(`created_at`),
    INDEX `idx_query_log_customer`(`customer_id`, `created_at`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
