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

/// Request message for GenerateAccessToken.
public struct GenerateAccessTokenRequest: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Required. Name of the workstation for which the access token should be
  /// generated.
  public var workstation: Swift.String = Swift.String()

  /// Optional. Port for which the access token should be generated. If
  /// specified, the generated access token grants access only to the
  /// specified port of the workstation. If specified, values must be within the
  /// range [1 - 65535]. If not specified, the generated access token grants
  /// access to all ports of the workstation.
  public var port: Swift.Int32 = Swift.Int32()

  /// Desired expiration or lifetime of the access token.
  public var expiration: OneOf_Expiration? = nil

  /// Initialize a new instance of `GenerateAccessTokenRequest`.
  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 = GenerateAccessTokenRequest().with { $0.expireTime = ... }
  /// ```
  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 expireTime = "expireTime"
    case ttl = "ttl"
    case workstation = "workstation"
    case port = "port"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.workstation = try container.decode(Swift.String.self, forKey: .workstation)
    self.port = try container.decode(Swift.Int32.self, forKey: .port)

    var expiration: OneOf_Expiration? = nil
    let expirationCheckAndSet = {
      if expiration != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'expiration'"))
      }
      expiration = $0
    }
    if let expireTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp?.self, forKey: .expireTime)
    {
      try expirationCheckAndSet(.expireTime(expireTime))
    }
    if let ttl = try container.decodeIfPresent(GoogleCloudWkt.Duration?.self, forKey: .ttl) {
      try expirationCheckAndSet(.ttl(ttl))
    }
    self.expiration = expiration
  }

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

    if let choice = self.expiration {
      switch choice {
      case .expireTime(let value):
        try container.encode(value, forKey: .expireTime)
      case .ttl(let value):
        try container.encode(value, forKey: .ttl)
      }
    }
  }

  /// Desired expiration or lifetime of the access token.
  public enum OneOf_Expiration: Codable, Equatable, Sendable {
    /// Desired expiration time of the access token. This value must
    /// be at most 24 hours in the future. If a value is not specified, the
    /// token's expiration time will be set to a default value of 1 hour in the
    /// future.
    indirect case expireTime(GoogleCloudWkt.Timestamp?)
    /// Desired lifetime duration of the access token. This value must
    /// be at most 24 hours. If a value is not specified, the token's lifetime
    /// will be set to a default value of 1 hour.
    indirect case ttl(GoogleCloudWkt.Duration?)
  }

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