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

  /// Represents a health source.
  ///
  /// A health source resource specifies the source resources and the health
  /// aggregation policy applied to the source resources to determine the
  /// aggregated health status.
  public struct HealthSource: 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 HealthSource. An up-to-date fingerprint
    /// must be provided in order to patch the HealthSource; Otherwise, the request
    /// will fail with error 412 conditionNotMet. To see the latest
    /// fingerprint, make a get() request to retrieve the
    /// HealthSource.
    public var fingerprint: Foundation.Data? = nil

    /// URL to the HealthAggregationPolicy resource. Must be set. Must
    /// be regional and in the same region as the HealthSource. Can be
    /// mutated.
    public var healthAggregationPolicy: Swift.String? = nil

    /// Output only. [Output Only] A unique identifier for this resource type. The server
    /// generates this identifier.
    public var id: Swift.UInt64? = nil

    /// Output only. [Output Only] Type of the resource. Alwayscompute#healthSource for health sources.
    public var kind: Swift.String? = nil

    /// Name of the resource. Provided by the client when the resource is created.
    /// The name must be 1-63 characters long, and comply withRFC1035.
    /// 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

    /// Output only. [Output Only] URL of the region where the health source resides.
    /// This field applies only to the regional resource. 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

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

    /// Specifies the type of the HealthSource. The only allowed value
    /// is BACKEND_SERVICE. Must be specified when theHealthSource is created, and cannot be mutated.
    public var sourceType: HealthSource.SourceType? = nil

    /// URLs to the source resources. Must be size 1. Must be aBackendService if
    /// the sourceType is BACKEND_SERVICE. TheBackendService must have load balancing schemeINTERNAL or INTERNAL_MANAGED and must be regional
    /// and in the same region as the HealthSource (cross-region
    /// deployment for INTERNAL_MANAGED is not supported). TheBackendService may use only IGs, MIGs, or NEGs of typeGCE_VM_IP or GCE_VM_IP_PORT. TheBackendService may not use haPolicy. Can be
    /// mutated.
    public var sources: [Swift.String] = []

    /// Initialize a new instance of `HealthSource`.
    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 = HealthSource().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 healthAggregationPolicy = "healthAggregationPolicy"
      case id = "id"
      case kind = "kind"
      case name = "name"
      case region = "region"
      case selfLink = "selfLink"
      case selfLinkWithId = "selfLinkWithId"
      case sourceType = "sourceType"
      case sources = "sources"
    }

    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.healthAggregationPolicy = try container.decodeIfPresent(
        Swift.String.self, forKey: .healthAggregationPolicy)
      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.region = try container.decodeIfPresent(Swift.String.self, forKey: .region)
      self.selfLink = try container.decodeIfPresent(Swift.String.self, forKey: .selfLink)
      self.selfLinkWithId = try container.decodeIfPresent(
        Swift.String.self, forKey: .selfLinkWithId)
      self.sourceType = try container.decodeIfPresent(
        HealthSource.SourceType.self, forKey: .sourceType)
      self.sources = try container.decode([Swift.String].self, forKey: .sources)
    }

    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.healthAggregationPolicy, forKey: .healthAggregationPolicy)
      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.region, forKey: .region)
      try container.encode(self.selfLink, forKey: .selfLink)
      try container.encode(self.selfLinkWithId, forKey: .selfLinkWithId)
      try container.encode(self.sourceType, forKey: .sourceType)
      try container.encode(self.sources, forKey: .sources)
    }

    /// The enumerated type for the [sourceType][google.cloud.compute.v1.HealthSource.sourceType] field.
    ///
    /// [google.cloud.compute.v1.HealthSource.sourceType]: <doc:HealthSource/SourceType>
    public enum SourceType: Codable, Equatable, Sendable {
      case backendService
      /// 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 = .backendService
      }

      /// 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 .backendService: return 0
        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 .backendService: return "BACKEND_SERVICE"
        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:SourceType/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "BACKEND_SERVICE": self = .backendService
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:SourceType/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .backendService
        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 .backendService: return try container.encode(0)
        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.HealthSource"
    }
    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
