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

/// An `AccessLevel` is a label that can be applied to requests to Google Cloud
/// services, along with a list of requirements necessary for the label to be
/// applied.
public struct AccessLevel: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Required. Resource name for the Access Level. The `short_name` component
  /// must begin with a letter and only include alphanumeric and '_'. Format:
  /// `accessPolicies/{access_policy}/accessLevels/{access_level}`. The maximum
  /// length of the `access_level` component is 50 characters.
  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 `AccessLevel` and its use. Does not affect behavior.
  public var description: Swift.String = Swift.String()

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

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

  /// Required. Describes the necessary conditions for the level to apply.
  public var level: OneOf_Level? = nil

  /// Initialize a new instance of `AccessLevel`.
  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 = AccessLevel().with { $0.name = ... }
  /// ```
  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 name = "name"
    case title = "title"
    case description = "description"
    case basic = "basic"
    case custom = "custom"
    case createTime = "createTime"
    case updateTime = "updateTime"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.name = try container.decode(Swift.String.self, forKey: .name)
    self.title = try container.decode(Swift.String.self, forKey: .title)
    self.description = try container.decode(Swift.String.self, forKey: .description)
    self.createTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .createTime)
    self.updateTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .updateTime)

    var level: OneOf_Level? = nil
    let levelCheckAndSet = {
      if level != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'level'"))
      }
      level = $0
    }
    if let basic = try container.decodeIfPresent(BasicLevel?.self, forKey: .basic) {
      try levelCheckAndSet(.basic(basic))
    }
    if let custom = try container.decodeIfPresent(CustomLevel?.self, forKey: .custom) {
      try levelCheckAndSet(.custom(custom))
    }
    self.level = level
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.name, forKey: .name)
    try container.encode(self.title, forKey: .title)
    try container.encode(self.description, forKey: .description)
    try container.encode(self.createTime, forKey: .createTime)
    try container.encode(self.updateTime, forKey: .updateTime)

    if let choice = self.level {
      switch choice {
      case .basic(let value):
        try container.encode(value, forKey: .basic)
      case .custom(let value):
        try container.encode(value, forKey: .custom)
      }
    }
  }

  /// Required. Describes the necessary conditions for the level to apply.
  public enum OneOf_Level: Codable, Equatable, Sendable {
    /// A `BasicLevel` composed of `Conditions`.
    indirect case basic(BasicLevel?)
    /// A `CustomLevel` written in the Common Expression Language.
    indirect case custom(CustomLevel?)
  }

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