// Copyright 2025 Envoy Project Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package envoy.extensions.geoip_providers.common.v3;

import "envoy/annotations/deprecation.proto";
import "udpa/annotations/status.proto";
import "validate/validate.proto";

option java_package = "io.envoyproxy.envoy.extensions.geoip_providers.common.v3";
option java_outer_classname = "CommonProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/geoip_providers/common/v3;commonv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: Common Geolocation Provider Configuration]
// Common geolocation provider :ref:`configuration overview <config_geoip_providers_common>`.
// Common configuration shared across geolocation providers.

message CommonGeoipProviderConfig {
  // The set of geolocation headers to add to request. If any of the configured headers is present
  // in the incoming request, it will be overridden by the :ref:`Geoip filter <config_http_filters_geoip>`.
  // [#next-free-field: 13]
  message GeolocationHeadersToAdd {
    // If set, the header will be used to populate the country ISO code associated with the IP address.
    string country = 1
        [(validate.rules).string = {well_known_regex: HTTP_HEADER_NAME ignore_empty: true}];

    // If set, the header will be used to populate the city associated with the IP address.
    string city = 2
        [(validate.rules).string = {well_known_regex: HTTP_HEADER_NAME ignore_empty: true}];

    // If set, the header will be used to populate the region ISO code associated with the IP address.
    // The least specific subdivision will be selected as region value.
    string region = 3
        [(validate.rules).string = {well_known_regex: HTTP_HEADER_NAME ignore_empty: true}];

    // If set, the header will be used to populate the ASN associated with the IP address.
    string asn = 4
        [(validate.rules).string = {well_known_regex: HTTP_HEADER_NAME ignore_empty: true}];

    // This field is being deprecated, use ``anon`` instead.
    string is_anon = 5 [
      deprecated = true,
      (validate.rules).string = {well_known_regex: HTTP_HEADER_NAME ignore_empty: true},
      (envoy.annotations.deprecated_at_minor_version) = "3.0"
    ];

    // If set, the IP address will be checked if it belongs to any type of anonymization network (e.g. VPN, public proxy etc)
    // and header will be populated with the check result. Header value will be set to either "true" or "false" depending on the check result.
    string anon = 12
        [(validate.rules).string = {well_known_regex: HTTP_HEADER_NAME ignore_empty: true}];

    // If set, the IP address will be checked if it belongs to a VPN and header will be populated with the check result.
    // Header value will be set to either "true" or "false" depending on the check result.
    string anon_vpn = 6
        [(validate.rules).string = {well_known_regex: HTTP_HEADER_NAME ignore_empty: true}];

    // If set, the IP address will be checked if it belongs to a hosting provider and header will be populated with the check result.
    // Header value will be set to either "true" or "false" depending on the check result.
    string anon_hosting = 7
        [(validate.rules).string = {well_known_regex: HTTP_HEADER_NAME ignore_empty: true}];

    // If set, the IP address will be checked if it belongs to a TOR exit node and header will be populated with the check result.
    // Header value will be set to either "true" or "false" depending on the check result.
    string anon_tor = 8
        [(validate.rules).string = {well_known_regex: HTTP_HEADER_NAME ignore_empty: true}];

    // If set, the IP address will be checked if it belongs to a public proxy and header will be populated with the check result.
    // Header value will be set to either "true" or "false" depending on the check result.
    string anon_proxy = 9
        [(validate.rules).string = {well_known_regex: HTTP_HEADER_NAME ignore_empty: true}];

    // If set, the header will be used to populate the ISP associated with the IP address.
    string isp = 10
        [(validate.rules).string = {well_known_regex: HTTP_HEADER_NAME ignore_empty: true}];

    // If set, the IP address will be checked if it belongs to the ISP named iCloud Private Relay and header will be populated with the check result.
    // Header value will be set to either "true" or "false" depending on the check result.
    string apple_private_relay = 11
        [(validate.rules).string = {well_known_regex: HTTP_HEADER_NAME ignore_empty: true}];
  }

  // Configuration for geolocation headers to add to request.
  GeolocationHeadersToAdd geo_headers_to_add = 1 [(validate.rules).message = {required: true}];
}
