# Detect if request has any query args
map $args $has_args {
    default 1;
    "" 0;
}

# Detect Magento/session cookies
map $http_cookie $has_mage_cookie {
    default 0;
    ~*PHPSESSID= 1;
    ~*private_content_version= 1;
}

# Detect marketing/tracking query params
map $args $is_marketing {
    default 0;
    ~*(^|&)(form_key|utm_[^=]*|gclid|fbclid|msclkid|g[a-z]*braid|gad_|p|image-type)= 1;
}

# Detect allowed admin/internal paths
map $uri $is_whitelisted_path {
    default 0;
    ~*(panelbomar|admin_link1|admin_link2) 1;
}

# Final decision
map "$has_args:$has_mage_cookie:$is_marketing:$is_whitelisted_path" $block_request {
    default 0;

    # Block ONLY when:
    # - has query args
    # - no session cookie
    # - not marketing
    # - not whitelisted path
    "1:0:0:0" 1;
}
