// 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

  /// Specifies the custom error response policy that must be applied when the
  /// backend service or backend bucket responds with an error.
  public struct CustomErrorResponsePolicy: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Specifies rules for returning error responses.
    ///
    /// In a given policy, if you specify rules for both a range of error codes
    /// as well as rules for specific error codes then rules with specific error
    /// codes have a higher priority. For example, assume that you configure a rule
    /// for 401 (Un-authorized) code, and another for all 4 series
    /// error codes (4XX). If the backend service returns a401, then the rule for 401 will be applied.
    /// However if the backend service returns a 403, the rule for4xx takes effect.
    public var errorResponseRules: [CustomErrorResponsePolicyCustomErrorResponseRule] = []

    /// The full or partial URL to the BackendBucket resource that
    /// contains the custom error content. Examples are:
    ///
    ///
    ///      - https://www.googleapis.com/compute/v1/projects/project/global/backendBuckets/myBackendBucket
    ///      - compute/v1/projects/project/global/backendBuckets/myBackendBucket
    ///      - global/backendBuckets/myBackendBucket
    ///
    /// If errorService is not specified at lower levels likepathMatcher, pathRule and routeRule,
    /// an errorService specified at a higher level in theUrlMap will be used. IfUrlMap.defaultCustomErrorResponsePolicy contains one or moreerrorResponseRules[], it must specifyerrorService.
    ///
    /// If load balancer cannot reach
    /// the backendBucket, a simple Not Found Error will
    /// be returned, with the original response code (oroverrideResponseCode if configured).
    ///
    /// errorService is not supported for internal or regionalHTTP/HTTPS load balancers.
    public var errorService: Swift.String? = nil

    /// Initialize a new instance of `CustomErrorResponsePolicy`.
    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 = CustomErrorResponsePolicy().with { $0.errorResponseRules = ... }
    /// ```
    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.CustomErrorResponsePolicy"
    }
    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
