// Code generated by sidekick. DO NOT EDIT.
//
// Copyright 2026 Google LLC
//
// 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
//
//     https://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.

#if RegionUrlMaps || UrlMaps
  import Foundation
  import GoogleCloudWkt

  public struct HttpRouteAction: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Specifies the cache policy configuration for matched traffic. Available
    /// only for Global `EXTERNAL_MANAGED` load balancer schemes. At least one
    /// property must be specified. This policy cannot be specified if any target
    /// backend has Identity-Aware Proxy enabled.
    public var cachePolicy: CachePolicy? = nil

    /// The specification for allowing client-side cross-origin requests. For more
    /// information about the W3C recommendation for cross-origin resource sharing
    /// (CORS), see Fetch API Living
    /// Standard.
    ///
    /// Not supported when the URL map is bound to a target gRPC proxy.
    public var corsPolicy: CorsPolicy? = nil

    /// The specification for fault injection introduced into traffic to test
    /// the resiliency of clients to backend service failure. As part of fault
    /// injection, when clients send requests to a backend service, delays can be
    /// introduced by a load balancer on a percentage of requests before sending
    /// those requests to the backend service. Similarly requests from clients can
    /// be aborted by the load balancer for a percentage of requests.timeout and retry_policy is ignored by clients
    /// that are configured with a fault_injection_policy if:
    /// 1. The traffic is generated by fault injection AND
    /// 2. The fault injection is not a delay fault injection.
    /// Fault injection is not supported with the classic Application Load Balancer
    /// . To see which load balancers support fault injection,
    /// see Load
    /// balancing: Routing and traffic management features.
    public var faultInjectionPolicy: HttpFaultInjection? = nil

    /// Specifies the maximum duration (timeout) for streams on the selected route.
    /// Unlike the timeout field where the timeout duration starts
    /// from the time the request has been fully processed (known as*end-of-stream*),
    /// the duration in this field is computed from the beginning of the stream
    /// until the response has been processed, including all retries. A
    /// stream that does not complete in this duration is closed.
    ///
    /// If not specified, this field uses the maximummaxStreamDuration value among all backend services associated
    /// with the route.
    ///
    /// This field is only allowed if the Url map is used with backend services
    /// with loadBalancingScheme set toINTERNAL_SELF_MANAGED.
    public var maxStreamDuration: Duration? = nil

    /// Specifies the policy on how requests intended for the route's backends
    /// are shadowed to a separate mirrored backend service. The load balancer does
    /// not wait for responses from the shadow service. Before sending traffic
    /// to the shadow service, the host / authority header is suffixed with-shadow.
    ///
    /// Not supported when the URL map is bound to a target gRPC proxy that
    /// has the validateForProxyless field set to true.
    public var requestMirrorPolicy: RequestMirrorPolicy? = nil

    /// Specifies the retry policy associated with this route.
    public var retryPolicy: HttpRetryPolicy? = nil

    /// Specifies the timeout for the selected route. Timeout is computed from the
    /// time the request has been fully processed (known as *end-of-stream*)
    /// up until the response has been processed. Timeout includes
    /// all retries.
    ///
    /// If not specified, this field uses the largest timeout among all backend
    /// services associated with the route.
    ///
    /// Not supported when the URL map is bound to a target gRPC proxy that
    /// has validateForProxyless field set to true.
    public var timeout: Duration? = nil

    /// The spec to modify the URL of the request, before forwarding the request
    /// to the matched service.
    ///
    ///  urlRewrite is the only action supported in UrlMaps
    /// for classic Application Load Balancers.
    ///
    /// Not supported when the URL map is bound to a target gRPC proxy that
    /// has the validateForProxyless field set to true.
    public var urlRewrite: UrlRewrite? = nil

    /// A list of weighted backend services to send traffic to when a route match
    /// occurs. The weights determine the fraction of traffic that flows to
    /// their corresponding backend service. If all traffic needs to
    /// go to a single backend service, there must be oneweightedBackendService with weight set to a non-zero number.
    ///
    /// After a backend service is identified and before forwarding
    /// the request to
    /// the backend service, advanced routing actions such as URL rewrites and
    /// header transformations are applied depending on additional settings
    /// specified in this HttpRouteAction.
    public var weightedBackendServices: [WeightedBackendService] = []

    /// Initialize a new instance of `HttpRouteAction`.
    public init() {}

    /// Use `config` to return a new instance of this object, with some fields updated.
    ///
    /// Commonly used to initialize the value, for example:
    ///
    /// ```
    /// let value = HttpRouteAction().with { $0.cachePolicy = ... }
    /// ```
    public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
      var copy = self
      try config(&copy)
      return copy
    }

    public static var _anyTypeUrl: Swift.String {
      return "type.googleapis.com/google.cloud.compute.v1.HttpRouteAction"
    }
    public init(fromAny any: GoogleCloudWkt.`Any`) throws {
      self = try GoogleCloudWkt._slowAnyDeserialize(Self.self, from: any)
    }
    public func _pack() throws -> GoogleCloudWkt.Struct {
      return try GoogleCloudWkt._slowAnySerialize(message: self)
    }
  }
#endif
