-- NGBVD integration_logs API access audit columns.
-- Prefer the Laravel migration because it checks existing columns safely.
-- If running SQL manually, confirm each column does not already exist before executing.

ALTER TABLE `integration_logs`
  ADD COLUMN `request_id` VARCHAR(80) NULL AFTER `uuid`,
  ADD COLUMN `route_name` VARCHAR(150) NULL AFTER `http_method`,
  ADD COLUMN `request_url` TEXT NULL AFTER `route_name`,
  ADD COLUMN `request_query_preview` TEXT NULL AFTER `request_payload_preview`,
  ADD COLUMN `request_headers_preview` TEXT NULL AFTER `request_query_preview`,
  ADD COLUMN `ip_address` VARCHAR(64) NULL AFTER `request_headers_preview`,
  ADD COLUMN `forwarded_for` VARCHAR(255) NULL AFTER `ip_address`,
  ADD COLUMN `user_agent` TEXT NULL AFTER `forwarded_for`,
  ADD COLUMN `geo_country` VARCHAR(100) NULL AFTER `user_agent`,
  ADD COLUMN `geo_city` VARCHAR(100) NULL AFTER `geo_country`,
  ADD COLUMN `data_accessed` TEXT NULL AFTER `case_reference`,
  ADD COLUMN `data_scope` TEXT NULL AFTER `data_accessed`,
  ADD COLUMN `allowed_district_ids` TEXT NULL AFTER `data_scope`,
  ADD COLUMN `partner_id` BIGINT UNSIGNED NULL AFTER `allowed_district_ids`,
  ADD COLUMN `duration_ms` INT UNSIGNED NULL AFTER `response_code`,
  ADD COLUMN `response_size_bytes` INT UNSIGNED NULL AFTER `duration_ms`,
  ADD COLUMN `response_record_count` INT UNSIGNED NULL AFTER `response_size_bytes`,
  ADD COLUMN `is_signed_request` TINYINT(1) NOT NULL DEFAULT 0 AFTER `response_record_count`,
  ADD COLUMN `signature_status` VARCHAR(50) NULL AFTER `is_signed_request`,
  ADD COLUMN `is_encrypted_payload` TINYINT(1) NOT NULL DEFAULT 0 AFTER `signature_status`,
  ADD COLUMN `rate_limit_per_minute` INT UNSIGNED NULL AFTER `is_encrypted_payload`,
  ADD COLUMN `rate_limit_remaining` INT UNSIGNED NULL AFTER `rate_limit_per_minute`,
  ADD COLUMN `request_started_at` TIMESTAMP NULL AFTER `rate_limit_remaining`,
  ADD COLUMN `request_completed_at` TIMESTAMP NULL AFTER `request_started_at`;
