// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

syntax = "proto3";

package hashicorp.consul.mesh.v2beta1;

import "pbmesh/v2beta1/pbproxystate/access_logs.proto";
import "pbmesh/v2beta1/pbproxystate/cluster.proto";
import "pbmesh/v2beta1/pbproxystate/endpoints.proto";
import "pbmesh/v2beta1/pbproxystate/escape_hatches.proto";
import "pbmesh/v2beta1/pbproxystate/listener.proto";
import "pbmesh/v2beta1/pbproxystate/references.proto";
import "pbmesh/v2beta1/pbproxystate/route.proto";
import "pbmesh/v2beta1/pbproxystate/transport_socket.proto";
import "pbresource/annotations.proto";
import "pbresource/resource.proto";

message ProxyStateTemplate {
  option (hashicorp.consul.resource.spec) = {scope: SCOPE_NAMESPACE};

  // ProxyState is the partially filled out ProxyState resource. The Endpoints, LeafCertificates and TrustBundles fields will need filling in after the resource is stored.
  ProxyState proxy_state = 1;

  // RequiredEndpoints is a map of arbitrary string names to endpoint refs that need fetching by the proxy state controller.
  map<string, pbproxystate.EndpointRef> required_endpoints = 2;

  // RequiredLeafCertificates is a map of arbitrary string names to leaf certificates that need fetching/generation by the proxy state controller.
  map<string, pbproxystate.LeafCertificateRef> required_leaf_certificates = 3;

  // RequiredTrustBundles is a map of arbitrary string names to trust bundle refs that need fetching by the proxy state controller.
  map<string, pbproxystate.TrustBundleRef> required_trust_bundles = 4;
}

message ProxyState {
  // Identity is a reference to the identity of the workload this proxy is for.
  hashicorp.consul.resource.Reference identity = 1;
  // Listeners is a list of listeners for this proxy.
  repeated pbproxystate.Listener listeners = 2;
  // Clusters is a map from cluster name to clusters. The keys are referenced from listeners or routes.
  map<string, pbproxystate.Cluster> clusters = 3;
  // Routes is a map from route name to routes. The keys are referenced from listeners.
  map<string, pbproxystate.Route> routes = 4;
  // Endpoints is a map from cluster name to endpoints.
  map<string, pbproxystate.Endpoints> endpoints = 5;
  // LeafCertificates is a map from UUID to leaf certificates.
  map<string, pbproxystate.LeafCertificate> leaf_certificates = 6;
  // TrustBundles is a map from peer name to trust bundles.
  map<string, pbproxystate.TrustBundle> trust_bundles = 7;
  // TLS has TLS configuration for this proxy.
  pbproxystate.TLS tls = 8;
  // Escape defines top level escape hatches. These are user configured json strings that configure an entire piece of listener or cluster Envoy configuration.
  pbproxystate.EscapeHatches escape = 9;
  // AccessLogs configures access logging for this proxy.
  pbproxystate.AccessLogs access_logs = 10;
}
