// 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.filters.network.generic_proxy.matcher.v3;

import "envoy/type/matcher/v3/string.proto";

import "xds/annotations/v3/status.proto";

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

option java_package = "io.envoyproxy.envoy.extensions.filters.network.generic_proxy.matcher.v3";
option java_outer_classname = "MatcherProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/generic_proxy/matcher/v3;matcherv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;
option (xds.annotations.v3.file_status).work_in_progress = true;

// [#protodoc-title: Generic Proxy Route Matcher Configuration]

// Used to match request service of the downstream request. Only applicable if a service provided
// by the application protocol.
// This is deprecated and should be replaced by HostMatchInput. This is kept for backward compatibility.
message ServiceMatchInput {
}

// Used to match request host of the generic downstream request. Only applicable if a host provided
// by the application protocol.
// This is same with the ServiceMatchInput and this should be preferred over ServiceMatchInput.
message HostMatchInput {
}

// Used to match request path of the generic downstream request. Only applicable if a path provided
// by the application protocol.
message PathMatchInput {
}

// Used to match request method of the generic downstream request. Only applicable if a method provided
// by the application protocol.
message MethodMatchInput {
}

// Used to match an arbitrary property of the generic downstream request.
// These properties are populated by the codecs of application protocols.
message PropertyMatchInput {
  // The property name to match on.
  string property_name = 1 [(validate.rules).string = {min_len: 1}];
}

// Used to match an whole generic downstream request.
message RequestMatchInput {
}

// Used to match an arbitrary key-value pair for headers, trailers or properties.
message KeyValueMatchEntry {
  // The key name to match on.
  string name = 1 [(validate.rules).string = {min_len: 1}];

  // The key value pattern.
  type.matcher.v3.StringMatcher string_match = 2 [(validate.rules).message = {required: true}];
}

// Custom matcher to match on the generic downstream request. This is used to match
// multiple fields of the downstream request and avoid complex combinations of
// HostMatchInput, PathMatchInput, MethodMatchInput and PropertyMatchInput.
message RequestMatcher {
  // Optional host pattern to match on. If not specified, any host will match.
  type.matcher.v3.StringMatcher host = 1;

  // Optional path pattern to match on. If not specified, any path will match.
  type.matcher.v3.StringMatcher path = 2;

  // Optional method pattern to match on. If not specified, any method will match.
  type.matcher.v3.StringMatcher method = 3;

  // Optional arbitrary properties to match on. If not specified, any properties
  // will match. The key is the property name and the value is the property value
  // to match on.
  repeated KeyValueMatchEntry properties = 4;
}
