-- === 04_http2_fields.sql — Ajout des colonnes HTTP/2 à http_logs ===
--
-- Migration pour les déploiements existants : ajoute les colonnes de
-- fingerprint HTTP/2 passif extraites par mod_reqin_log via son hook
-- process_connection (APR_HOOK_FIRST, AP_MODE_SPECULATIVE).
--
-- Format du fingerprint Akamai (h2_fingerprint) :
--   Chrome  : "1:65536,2:0,4:6291456,6:262144|15663105|0|m,a,s,p"
--   Firefox : "1:65536,4:131072,5:16384|12517377|0|m,p,s,a"
--   Safari  : "1:4096,3:100,4:65535|10485760|0|m,a,s,p"
--
-- Appliquer avec :
--   clickhouse-client --multiquery < 04_http2_fields.sql

-- Champs composites (fingerprint global + valeurs agrégées)
ALTER TABLE ja4_logs.http_logs
    ADD COLUMN IF NOT EXISTS `h2_fingerprint`   String DEFAULT '' CODEC(ZSTD(3));

ALTER TABLE ja4_logs.http_logs
    ADD COLUMN IF NOT EXISTS `h2_settings_fp`   String DEFAULT '' CODEC(ZSTD(3));

ALTER TABLE ja4_logs.http_logs
    ADD COLUMN IF NOT EXISTS `h2_window_update` UInt32 DEFAULT 0;

ALTER TABLE ja4_logs.http_logs
    ADD COLUMN IF NOT EXISTS `h2_pseudo_order`  LowCardinality(String) DEFAULT '';

ALTER TABLE ja4_logs.http_logs
    ADD COLUMN IF NOT EXISTS `h2_has_priority`  UInt8 DEFAULT 0;

-- Paramètres SETTINGS individuels (RFC 9113 §6.5.2)
-- Valeur -1 = paramètre absent du preface client (non envoyé)
ALTER TABLE ja4_logs.http_logs
    ADD COLUMN IF NOT EXISTS `h2_header_table_size`       Int32 DEFAULT -1;

ALTER TABLE ja4_logs.http_logs
    ADD COLUMN IF NOT EXISTS `h2_enable_push`             Int32 DEFAULT -1;

ALTER TABLE ja4_logs.http_logs
    ADD COLUMN IF NOT EXISTS `h2_max_concurrent_streams`  Int32 DEFAULT -1;

ALTER TABLE ja4_logs.http_logs
    ADD COLUMN IF NOT EXISTS `h2_initial_window_size`     Int64 DEFAULT -1;

ALTER TABLE ja4_logs.http_logs
    ADD COLUMN IF NOT EXISTS `h2_max_frame_size`          Int32 DEFAULT -1;

ALTER TABLE ja4_logs.http_logs
    ADD COLUMN IF NOT EXISTS `h2_max_header_list_size`    Int32 DEFAULT -1;

ALTER TABLE ja4_logs.http_logs
    ADD COLUMN IF NOT EXISTS `h2_enable_connect_protocol` Int32 DEFAULT -1;
