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

import Foundation
import GoogleCloudWkt

/// A resource representing a network that connects the various components of a
/// cluster together.
public struct NetworkResource: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Immutable. Configuration for this network resource, which describes how it
  /// should be created or imported. This field only controls how the network
  /// resource is initially created or imported. Subsequent changes to the
  /// network resource should be made via the resource's API and will not be
  /// reflected in the configuration.
  public var config: NetworkResourceConfig? = nil

  /// Reference to the network resource in Google Cloud. Exactly one of these
  /// fields will be populated based on the configured type of network resource.
  public var reference: OneOf_Reference? = nil

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

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.config = try container.decodeIfPresent(NetworkResourceConfig.self, forKey: .config)

    var reference: OneOf_Reference? = nil
    let referenceCheckAndSet = {
      if reference != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'reference'"))
      }
      reference = $0
    }
    if let network = try container.decodeIfPresent(NetworkReference?.self, forKey: .network) {
      try referenceCheckAndSet(.network(network))
    }
    self.reference = reference
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.config, forKey: .config)

    if let choice = self.reference {
      switch choice {
      case .network(let value):
        try container.encode(value, forKey: .network)
      }
    }
  }

  /// Reference to the network resource in Google Cloud. Exactly one of these
  /// fields will be populated based on the configured type of network resource.
  public enum OneOf_Reference: Codable, Equatable, Sendable {
    /// Reference to a network in Google Compute Engine.
    indirect case network(NetworkReference?)
  }

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