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

/// The ServiceConnectionPolicy resource.
public struct ServiceConnectionPolicy: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Immutable. The name of a ServiceConnectionPolicy.
  /// Format:
  /// projects/{project}/locations/{location}/serviceConnectionPolicies/{service_connection_policy}
  /// See: https://google.aip.dev/122#fields-representing-resource-names
  public var name: Swift.String = Swift.String()

  /// Output only. Time when the ServiceConnectionPolicy was created.
  public var createTime: GoogleCloudWkt.Timestamp? = nil

  /// Output only. Time when the ServiceConnectionPolicy was updated.
  public var updateTime: GoogleCloudWkt.Timestamp? = nil

  /// User-defined labels.
  public var labels: [Swift.String: Swift.String] = [:]

  /// A description of this resource.
  public var description: Swift.String = Swift.String()

  /// The resource path of the consumer network.
  /// Example:
  /// - projects/{projectNumOrId}/global/networks/{resourceId}.
  public var network: Swift.String = Swift.String()

  /// The service class identifier for which this ServiceConnectionPolicy is for.
  /// The service class identifier is a unique, symbolic representation of a
  /// ServiceClass. It is provided by the Service Producer. Google services have
  /// a prefix of gcp or google-cloud. For example, gcp-memorystore-redis or
  /// google-cloud-sql. 3rd party services do not. For example,
  /// test-service-a3dfcx.
  public var serviceClass: Swift.String = Swift.String()

  /// Output only. The type of underlying resources used to create the
  /// connection.
  public var infrastructure: Infrastructure = Infrastructure()

  /// Configuration used for Private Service Connect connections. Used when
  /// Infrastructure is PSC.
  public var pscConfig: ServiceConnectionPolicy.PscConfig? = nil

  /// Output only. [Output only] Information about each Private Service Connect
  /// connection.
  public var pscConnections: [ServiceConnectionPolicy.PscConnection] = []

  /// Optional. The etag is computed by the server, and may be sent on update and
  /// delete requests to ensure the client has an up-to-date value before
  /// proceeding.
  public var etag: Swift.String? = nil

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

  /// Configuration used for Private Service Connect connections. Used when
  /// Infrastructure is PSC.
  public struct PscConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// The resource paths of subnetworks to use for IP address management.
    /// Example:
    /// projects/{projectNumOrId}/regions/{region}/subnetworks/{resourceId}.
    public var subnetworks: [Swift.String] = []

    /// Optional. Max number of PSC connections for this policy.
    public var limit: Swift.Int64? = nil

    /// Required. ProducerInstanceLocation is used to specify which authorization
    /// mechanism to use to determine which projects the Producer instance can be
    /// within.
    public var producerInstanceLocation:
      ServiceConnectionPolicy.PscConfig.ProducerInstanceLocation = ServiceConnectionPolicy.PscConfig
        .ProducerInstanceLocation()

    /// Optional. List of Projects, Folders, or Organizations from where the
    /// Producer instance can be within. For example, a network administrator can
    /// provide both 'organizations/foo' and 'projects/bar' as
    /// allowed_google_producers_resource_hierarchy_levels. This allowlists this
    /// network to connect with any Producer instance within the 'foo'
    /// organization or the 'bar' project. By default,
    /// allowed_google_producers_resource_hierarchy_level is empty. The format
    /// for each allowed_google_producers_resource_hierarchy_level is <resource
    /// type>/<id> where <resource type> is one of 'projects', 'folders', or
    /// 'organizations' and <id> is either the ID or the number of the resource
    /// type. Format for each allowed_google_producers_resource_hierarchy_level
    /// value: 'projects/<project_id_or_number>' or 'folders/<folder_id>' or
    /// 'organizations/<organization_id>'
    /// Eg. [projects/my-project-id, projects/567, folders/891,
    /// organizations/123]
    public var allowedGoogleProducersResourceHierarchyLevel: [Swift.String] = []

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

    /// ProducerInstanceLocation is used to specify which authorization mechanism
    /// to use to determine which projects the Producer instance can be within.
    public enum ProducerInstanceLocation: Codable, Equatable, Sendable {
      /// Producer instance location is not specified. When this option is
      /// chosen, then the PSC connections created by this
      /// ServiceConnectionPolicy must be within the same project as the Producer
      /// instance. This is the default ProducerInstanceLocation value.
      /// To allow for PSC connections from this network to other networks, use
      /// the CUSTOM_RESOURCE_HIERARCHY_LEVELS option.
      case unspecified
      /// Producer instance must be within one of the values provided in
      /// allowed_google_producers_resource_hierarchy_level.
      case customResourceHierarchyLevels
      /// 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 = .unspecified
      }

      /// 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 .unspecified: return 0
        case .customResourceHierarchyLevels: 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 .unspecified: return "PRODUCER_INSTANCE_LOCATION_UNSPECIFIED"
        case .customResourceHierarchyLevels: return "CUSTOM_RESOURCE_HIERARCHY_LEVELS"
        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:ProducerInstanceLocation/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "PRODUCER_INSTANCE_LOCATION_UNSPECIFIED": self = .unspecified
        case "CUSTOM_RESOURCE_HIERARCHY_LEVELS": self = .customResourceHierarchyLevels
        default: self = .unknownStringValue(stringValue)
        }
      }

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

  /// Information about a specific Private Service Connect connection.
  public struct PscConnection: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// State of the PSC Connection
    public var state: ServiceConnectionPolicy.State = ServiceConnectionPolicy.State()

    /// The resource reference of the PSC Forwarding Rule within the consumer
    /// VPC.
    public var consumerForwardingRule: Swift.String = Swift.String()

    /// The resource reference of the consumer address.
    public var consumerAddress: Swift.String = Swift.String()

    /// The error type indicates whether the error is consumer facing, producer
    /// facing or system internal.
    @available(*, deprecated)
    public var errorType: ConnectionErrorType = ConnectionErrorType()

    /// The most recent error during operating this connection.
    /// Deprecated, please use error_info instead.
    @available(*, deprecated)
    public var error: GoogleRpc.Status? = nil

    /// The last Compute Engine operation to setup PSC connection.
    public var gceOperation: Swift.String = Swift.String()

    /// The project where the PSC connection is created.
    public var consumerTargetProject: Swift.String = Swift.String()

    /// The PSC connection id of the PSC forwarding rule.
    public var pscConnectionId: Swift.String = Swift.String()

    /// Output only. The error info for the latest error during operating this
    /// connection.
    public var errorInfo: GoogleRpc.ErrorInfo? = nil

    /// Output only. The URI of the subnetwork selected to allocate IP address
    /// for this connection.
    public var selectedSubnetwork: Swift.String = Swift.String()

    /// Immutable. Deprecated. Use producer_instance_metadata instead.
    /// An immutable identifier for the producer instance.
    @available(*, deprecated)
    public var producerInstanceId: Swift.String = Swift.String()

    /// Immutable. An immutable map for the producer instance metadata.
    public var producerInstanceMetadata: [Swift.String: Swift.String] = [:]

    /// Output only. [Output only] The service class associated with this PSC
    /// Connection. The value is derived from the SCPolicy and matches the
    /// service class name provided by the customer.
    public var serviceClass: Swift.String = Swift.String()

    /// The requested IP version for the PSC connection.
    public var ipVersion: IPVersion? = nil

    /// Initialize a new instance of `PscConnection`.
    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 = PscConnection().with { $0.state = ... }
    /// ```
    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.networkconnectivity.v1.ServiceConnectionPolicy.PscConnection"
    }
    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)
    }
  }

  /// The state of the PSC connection.
  /// We reserve the right to add more states without notice in the future.
  /// Users should not use exhaustive switch statements on this enum.
  /// See https://google.aip.dev/216.
  public enum State: Codable, Equatable, Sendable {
    /// An invalid state as the default case.
    case unspecified
    /// The connection has been created successfully. However, for the
    /// up-to-date connection status, please use the created forwarding rule's
    /// "PscConnectionStatus" as the source of truth.
    case active
    /// The connection is not functional since some resources on the connection
    /// fail to be created.
    case failed
    /// The connection is being created.
    case creating
    /// The connection is being deleted.
    case deleting
    /// The connection is being repaired to complete creation.
    case createRepairing
    /// The connection is being repaired to complete deletion.
    case deleteRepairing
    /// 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 = .unspecified
    }

    /// 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 .unspecified: return 0
      case .active: return 1
      case .failed: return 2
      case .creating: return 3
      case .deleting: return 4
      case .createRepairing: return 5
      case .deleteRepairing: return 6
      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 .unspecified: return "STATE_UNSPECIFIED"
      case .active: return "ACTIVE"
      case .failed: return "FAILED"
      case .creating: return "CREATING"
      case .deleting: return "DELETING"
      case .createRepairing: return "CREATE_REPAIRING"
      case .deleteRepairing: return "DELETE_REPAIRING"
      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:State/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "STATE_UNSPECIFIED": self = .unspecified
      case "ACTIVE": self = .active
      case "FAILED": self = .failed
      case "CREATING": self = .creating
      case "DELETING": self = .deleting
      case "CREATE_REPAIRING": self = .createRepairing
      case "DELETE_REPAIRING": self = .deleteRepairing
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:State/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .active
      case 2: self = .failed
      case 3: self = .creating
      case 4: self = .deleting
      case 5: self = .createRepairing
      case 6: self = .deleteRepairing
      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 .unspecified: return try container.encode(0)
      case .active: return try container.encode(1)
      case .failed: return try container.encode(2)
      case .creating: return try container.encode(3)
      case .deleting: return try container.encode(4)
      case .createRepairing: return try container.encode(5)
      case .deleteRepairing: return try container.encode(6)
      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.networkconnectivity.v1.ServiceConnectionPolicy"
  }
  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)
  }
}
