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

/// `ServicePerimeter` describes a set of Google Cloud resources which can freely
/// import and export data amongst themselves, but not export outside of the
/// `ServicePerimeter`. If a request with a source within this `ServicePerimeter`
/// has a target outside of the `ServicePerimeter`, the request will be blocked.
/// Otherwise the request is allowed. There are two types of Service Perimeter -
/// Regular and Bridge. Regular Service Perimeters cannot overlap, a single
/// Google Cloud project can only belong to a single regular Service Perimeter.
/// Service Perimeter Bridges can contain only Google Cloud projects as members,
/// a single Google Cloud project may belong to multiple Service Perimeter
/// Bridges.
public struct ServicePerimeter: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Required. Resource name for the ServicePerimeter.  The `short_name`
  /// component must begin with a letter and only include alphanumeric and '_'.
  /// Format:
  /// `accessPolicies/{access_policy}/servicePerimeters/{service_perimeter}`
  public var name: Swift.String = Swift.String()

  /// Human readable title. Must be unique within the Policy.
  public var title: Swift.String = Swift.String()

  /// Description of the `ServicePerimeter` and its use. Does not affect
  /// behavior.
  public var description: Swift.String = Swift.String()

  /// Output only. Time the `ServicePerimeter` was created in UTC.
  public var createTime: GoogleCloudWkt.Timestamp? = nil

  /// Output only. Time the `ServicePerimeter` was updated in UTC.
  public var updateTime: GoogleCloudWkt.Timestamp? = nil

  /// Perimeter type indicator. A single project is
  /// allowed to be a member of single regular perimeter, but multiple service
  /// perimeter bridges. A project cannot be a included in a perimeter bridge
  /// without being included in regular perimeter. For perimeter bridges,
  /// the restricted service list as well as access level lists must be
  /// empty.
  public var perimeterType: ServicePerimeter.PerimeterType = ServicePerimeter.PerimeterType()

  /// Current ServicePerimeter configuration. Specifies sets of resources,
  /// restricted services and access levels that determine perimeter
  /// content and boundaries.
  public var status: ServicePerimeterConfig? = nil

  /// Proposed (or dry run) ServicePerimeter configuration. This configuration
  /// allows to specify and test ServicePerimeter configuration without enforcing
  /// actual access restrictions. Only allowed to be set when the
  /// "use_explicit_dry_run_spec" flag is set.
  public var spec: ServicePerimeterConfig? = nil

  /// Use explicit dry run spec flag. Ordinarily, a dry-run spec implicitly
  /// exists  for all Service Perimeters, and that spec is identical to the
  /// status for those Service Perimeters. When this flag is set, it inhibits the
  /// generation of the implicit spec, thereby allowing the user to explicitly
  /// provide a configuration ("spec") to use in a dry-run version of the Service
  /// Perimeter. This allows the user to test changes to the enforced config
  /// ("status") without actually enforcing them. This testing is done through
  /// analyzing the differences between currently enforced and suggested
  /// restrictions. use_explicit_dry_run_spec must bet set to True if any of the
  /// fields in the spec are set to non-default values.
  public var useExplicitDryRunSpec: Swift.Bool = Swift.Bool()

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

  /// Specifies the type of the Perimeter. There are two types: regular and
  /// bridge. Regular Service Perimeter contains resources, access levels, and
  /// restricted services. Every resource can be in at most ONE
  /// regular Service Perimeter.
  ///
  /// In addition to being in a regular service perimeter, a resource can also
  /// be in zero or more perimeter bridges.  A perimeter bridge only contains
  /// resources.  Cross project operations are permitted if all effected
  /// resources share some perimeter (whether bridge or regular). Perimeter
  /// Bridge does not contain access levels or services: those are governed
  /// entirely by the regular perimeter that resource is in.
  ///
  /// Perimeter Bridges are typically useful when building more complex toplogies
  /// with many independent perimeters that need to share some data with a common
  /// perimeter, but should not be able to share data among themselves.
  public enum PerimeterType: Codable, Equatable, Sendable {
    /// Regular Perimeter.
    case regular
    /// Perimeter Bridge.
    case bridge
    /// 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 = .regular
    }

    /// 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 .regular: return 0
      case .bridge: 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 .regular: return "PERIMETER_TYPE_REGULAR"
      case .bridge: return "PERIMETER_TYPE_BRIDGE"
      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:PerimeterType/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "PERIMETER_TYPE_REGULAR": self = .regular
      case "PERIMETER_TYPE_BRIDGE": self = .bridge
      default: self = .unknownStringValue(stringValue)
      }
    }

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