// 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 RegionHealthCheckServices
  import Foundation
  import GoogleCloudWkt

  /// Represents a Health-Check as a Service resource.
  public struct HealthCheckService: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Output only. [Output Only] Creation timestamp inRFC3339
    /// text format.
    public var creationTimestamp: Swift.String? = nil

    /// An optional description of this resource. Provide this property when you
    /// create the resource.
    public var description: Swift.String? = nil

    /// Fingerprint of this resource. A hash of the contents stored in this object.
    /// This field is used in optimistic locking. This field will be ignored when
    /// inserting a HealthCheckService. An up-to-date fingerprint must
    /// be provided in order to patch/update the HealthCheckService; Otherwise, the
    /// request will fail with error 412 conditionNotMet. To see the
    /// latest fingerprint, make a get() request to retrieve the
    /// HealthCheckService.
    public var fingerprint: Foundation.Data? = nil

    /// A list of URLs to the HealthCheck resources. Must have
    /// at least one HealthCheck, and not more than 10 for regionalHealthCheckService, and not more than 1 for globalHealthCheckService.HealthCheck resources must haveportSpecification=USE_SERVING_PORT orportSpecification=USE_FIXED_PORT. For
    /// regional HealthCheckService, theHealthCheck must be regional and in the same
    /// region. For global HealthCheckService,HealthCheck must be global. Mix of regional and globalHealthChecks is not supported. Multiple regionalHealthChecks must belong to the same region. RegionalHealthChecks must belong to the same region as zones ofNetworkEndpointGroups. For globalHealthCheckService using globalINTERNET_IP_PORT NetworkEndpointGroups, the
    /// global HealthChecks must specify sourceRegions,
    /// and HealthChecks that specify sourceRegions can
    /// only be used with global INTERNET_IP_PORTNetworkEndpointGroups.
    public var healthChecks: [Swift.String] = []

    /// Optional. Policy for how the results from multiple health checks
    /// for the same endpoint are aggregated. Defaults to NO_AGGREGATION
    /// if unspecified.
    ///
    ///    - NO_AGGREGATION. An EndpointHealth message is
    ///    returned for each  pair in the health check
    ///    service.
    ///    - AND. If any health check of an endpoint reportsUNHEALTHY, then UNHEALTHY is theHealthState of the endpoint. If all health checks reportHEALTHY, the HealthState of the endpoint isHEALTHY.
    ///
    /// .
    /// This is only allowed with regional HealthCheckService.
    public var healthStatusAggregationPolicy: HealthCheckService.HealthStatusAggregationPolicy? =
      nil

    /// Output only. [Output Only] The unique identifier for the resource. This identifier is
    /// defined by the server.
    public var id: Swift.UInt64? = nil

    /// Output only. [Output only] Type of the resource. Alwayscompute#healthCheckServicefor health check services.
    public var kind: Swift.String? = nil

    /// Name of the resource. The name must be 1-63 characters long, and comply
    /// with RFC1035. Specifically, the name must be 1-63 characters
    /// long and match the regular expression
    /// `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first character
    /// must be a lowercase letter, and all following characters must be a dash,
    /// lowercase letter, or digit, except the last character, which cannot be a
    /// dash.
    public var name: Swift.String? = nil

    /// A list of URLs to the NetworkEndpointGroup
    /// resources. Must not have more than 100.  For regionalHealthCheckService, NEGs must be in
    /// zones in the region of the HealthCheckService. For globalHealthCheckServices, the NetworkEndpointGroups
    /// must be global INTERNET_IP_PORT.
    public var networkEndpointGroups: [Swift.String] = []

    /// A list of URLs to the NotificationEndpoint
    /// resources. Must not have more than 10.  A list of endpoints for
    /// receiving notifications of change in health status. For regionalHealthCheckService,NotificationEndpoint must be regional and in the
    /// same region. For global HealthCheckService,NotificationEndpoint must be global.
    public var notificationEndpoints: [Swift.String] = []

    /// Output only. [Output Only] URL of the region where the health check service
    /// resides. This field is not applicable to global health check services.
    /// You must specify this field as part of the HTTP request URL. It is
    /// not settable as a field in the request body.
    public var region: Swift.String? = nil

    /// Output only. [Output Only] Server-defined URL for the resource.
    public var selfLink: Swift.String? = nil

    /// Initialize a new instance of `HealthCheckService`.
    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 = HealthCheckService().with { $0.creationTimestamp = ... }
    /// ```
    public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
      var copy = self
      try config(&copy)
      return copy
    }

    private enum CodingKeys: Swift.String, CodingKey {
      case creationTimestamp = "creationTimestamp"
      case description = "description"
      case fingerprint = "fingerprint"
      case healthChecks = "healthChecks"
      case healthStatusAggregationPolicy = "healthStatusAggregationPolicy"
      case id = "id"
      case kind = "kind"
      case name = "name"
      case networkEndpointGroups = "networkEndpointGroups"
      case notificationEndpoints = "notificationEndpoints"
      case region = "region"
      case selfLink = "selfLink"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)
      self.creationTimestamp = try container.decodeIfPresent(
        Swift.String.self, forKey: .creationTimestamp)
      self.description = try container.decodeIfPresent(Swift.String.self, forKey: .description)
      if let s = try container.decodeIfPresent(Swift.String.self, forKey: .fingerprint) {
        guard let v = GoogleCloudWkt._DiscoveryBase64.decode(s) else {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath, debugDescription: "Expected url-safe encoded value")
          )
        }
        self.fingerprint = v
      }
      self.healthChecks = try container.decode([Swift.String].self, forKey: .healthChecks)
      self.healthStatusAggregationPolicy = try container.decodeIfPresent(
        HealthCheckService.HealthStatusAggregationPolicy.self,
        forKey: .healthStatusAggregationPolicy)
      self.id = try container.decodeIfPresent(Swift.UInt64.self, forKey: .id)
      self.kind = try container.decodeIfPresent(Swift.String.self, forKey: .kind)
      self.name = try container.decodeIfPresent(Swift.String.self, forKey: .name)
      self.networkEndpointGroups = try container.decode(
        [Swift.String].self, forKey: .networkEndpointGroups)
      self.notificationEndpoints = try container.decode(
        [Swift.String].self, forKey: .notificationEndpoints)
      self.region = try container.decodeIfPresent(Swift.String.self, forKey: .region)
      self.selfLink = try container.decodeIfPresent(Swift.String.self, forKey: .selfLink)
    }

    public func encode(to encoder: Encoder) throws {
      var container = encoder.container(keyedBy: CodingKeys.self)
      try container.encode(self.creationTimestamp, forKey: .creationTimestamp)
      try container.encode(self.description, forKey: .description)
      if let v = fingerprint {
        try container.encode(
          GoogleCloudWkt._DiscoveryBase64.encode(v), forKey: .fingerprint
        )
      }
      try container.encode(self.healthChecks, forKey: .healthChecks)
      try container.encode(
        self.healthStatusAggregationPolicy, forKey: .healthStatusAggregationPolicy)
      try container.encode(self.id, forKey: .id)
      try container.encode(self.kind, forKey: .kind)
      try container.encode(self.name, forKey: .name)
      try container.encode(self.networkEndpointGroups, forKey: .networkEndpointGroups)
      try container.encode(self.notificationEndpoints, forKey: .notificationEndpoints)
      try container.encode(self.region, forKey: .region)
      try container.encode(self.selfLink, forKey: .selfLink)
    }

    /// The enumerated type for the [healthStatusAggregationPolicy][google.cloud.compute.v1.HealthCheckService.healthStatusAggregationPolicy] field.
    ///
    /// [google.cloud.compute.v1.HealthCheckService.healthStatusAggregationPolicy]: <doc:HealthCheckService/HealthStatusAggregationPolicy>
    public enum HealthStatusAggregationPolicy: Codable, Equatable, Sendable {
      /// If any backend's health check reports UNHEALTHY,
      /// then UNHEALTHY is the HealthState of
      /// the entire health check service. If all backend's are healthy,
      /// the HealthState of the health check service isHEALTHY.
      case and
      /// An EndpointHealth message is returned for each
      /// backend in the health check service.
      case noAggregation
      /// Encodes an unknown integer value.
      ///
      /// The most common cause for an unknown values is for the service to send
      /// a value unknown to the library. We recommend you update your library to
      /// the latest version.
      case unknownIntValue(Int)
      /// Encodes an unknown string value.
      ///
      /// The most common cause for an unknown values is for the service to send
      /// a value unknown to the library. We recommend you update your library to
      /// the latest version.
      case unknownStringValue(String)

      public init() {
        self = .and
      }

      /// Returns the integer value associated with the enumeration.
      ///
      /// If the enumeration was initialized with an unknown string value, this returns `nil`.
      public var intValue: Int? {
        switch self {
        case .and: return 0
        case .noAggregation: return 1
        case .unknownIntValue(let v): return v
        case .unknownStringValue: return nil
        }
      }

      /// Returns the string value (or name) associated with the enumeration.
      ///
      /// If the enumeration was initialized with an unknown integer value, this returns `nil`.
      public var stringValue: Swift.String? {
        switch self {
        case .and: return "AND"
        case .noAggregation: return "NO_AGGREGATION"
        case .unknownIntValue: return nil
        case .unknownStringValue(let v): return v
        }
      }

      /// Initialize from a string value.
      ///
      /// If the value is unknown, this initializes to [`unknownStringValue`](doc:HealthStatusAggregationPolicy/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "AND": self = .and
        case "NO_AGGREGATION": self = .noAggregation
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:HealthStatusAggregationPolicy/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .and
        case 1: self = .noAggregation
        default: self = .unknownIntValue(intValue)
        }
      }

      public init(from decoder: Decoder) throws {
        let container = try decoder.singleValueContainer()
        if let v = try? container.decode(Int.self) {
          self.init(intValue: v)
          return
        }
        if let s = try? container.decode(String.self) {
          if let v = Int(s) {
            self.init(intValue: v)
          } else {
            self.init(stringValue: s)
          }
          return
        }
        throw DecodingError.dataCorruptedError(
          in: container, debugDescription: "Expected enum value, must be integer or string.")
      }

      public func encode(to encoder: Encoder) throws {
        var container = encoder.singleValueContainer()
        switch self {
        case .and: return try container.encode(0)
        case .noAggregation: return try container.encode(1)
        case .unknownIntValue(let v): return try container.encode(v)
        case .unknownStringValue(let v): return try container.encode(v)
        }
      }
    }

    public static var _anyTypeUrl: Swift.String {
      return "type.googleapis.com/google.cloud.compute.v1.HealthCheckService"
    }
    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
