-- Journal d'audit Amazon SP-API / Menadim Amazon
-- La table est aussi créée automatiquement par app_storage_ensure_schema().

CREATE TABLE IF NOT EXISTS `amazon_api_logs` (
    `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    `created_at` VARCHAR(40) NOT NULL,
    `source` VARCHAR(120) NOT NULL DEFAULT '',
    `user_id` VARCHAR(120) NULL,
    `action` VARCHAR(80) NOT NULL DEFAULT '',
    `method` VARCHAR(10) NOT NULL DEFAULT '',
    `endpoint` VARCHAR(255) NOT NULL DEFAULT '',
    `marketplace_id` VARCHAR(40) NULL,
    `asin` VARCHAR(20) NULL,
    `sku` VARCHAR(160) NULL,
    `feed_id` VARCHAR(120) NULL,
    `feed_document_id` VARCHAR(120) NULL,
    `http_status` INT NULL,
    `ok` TINYINT(1) NOT NULL DEFAULT 0,
    `duration_ms` INT NULL,
    `amazon_request_id` VARCHAR(120) NULL,
    `request_payload` LONGTEXT NULL,
    `response_payload` LONGTEXT NULL,
    `error_message` TEXT NULL,
    PRIMARY KEY (`id`),
    KEY `idx_amazon_api_logs_created_at` (`created_at`),
    KEY `idx_amazon_api_logs_action` (`action`),
    KEY `idx_amazon_api_logs_marketplace` (`marketplace_id`),
    KEY `idx_amazon_api_logs_sku` (`sku`),
    KEY `idx_amazon_api_logs_asin` (`asin`),
    KEY `idx_amazon_api_logs_ok` (`ok`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
