// 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 request for the customer to approve access to a resource.
public struct ApprovalRequest: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// The resource name of the request. Format is
  /// "{projects|folders|organizations}/{id}/approvalRequests/{approval_request}".
  public var name: Swift.String = Swift.String()

  /// The resource for which approval is being requested. The format of the
  /// resource name is defined at
  /// https://cloud.google.com/apis/design/resource_names. The resource name here
  /// may either be a "full" resource name (e.g.
  /// "//library.googleapis.com/shelves/shelf1/books/book2") or a "relative"
  /// resource name (e.g. "shelves/shelf1/books/book2") as described in the
  /// resource name specification.
  public var requestedResourceName: Swift.String = Swift.String()

  /// Properties related to the resource represented by requested_resource_name.
  public var requestedResourceProperties: ResourceProperties? = nil

  /// The justification for which approval is being requested.
  public var requestedReason: AccessReason? = nil

  /// The locations for which approval is being requested.
  public var requestedLocations: AccessLocations? = nil

  /// The time at which approval was requested.
  public var requestTime: GoogleCloudWkt.Timestamp? = nil

  /// The requested expiration for the approval. If the request is approved,
  /// access will be granted from the time of approval until the expiration time.
  public var requestedExpiration: GoogleCloudWkt.Timestamp? = nil

  /// The current decision on the approval request.
  public var decision: OneOf_Decision? = nil

  /// Initialize a new instance of `ApprovalRequest`.
  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 = ApprovalRequest().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 requestedResourceName = "requestedResourceName"
    case requestedResourceProperties = "requestedResourceProperties"
    case requestedReason = "requestedReason"
    case requestedLocations = "requestedLocations"
    case requestTime = "requestTime"
    case requestedExpiration = "requestedExpiration"
    case approve = "approve"
    case dismiss = "dismiss"
  }

  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.requestedResourceName = try container.decode(
      Swift.String.self, forKey: .requestedResourceName)
    self.requestedResourceProperties = try container.decodeIfPresent(
      ResourceProperties.self, forKey: .requestedResourceProperties)
    self.requestedReason = try container.decodeIfPresent(
      AccessReason.self, forKey: .requestedReason)
    self.requestedLocations = try container.decodeIfPresent(
      AccessLocations.self, forKey: .requestedLocations)
    self.requestTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .requestTime)
    self.requestedExpiration = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .requestedExpiration)

    var decision: OneOf_Decision? = nil
    let decisionCheckAndSet = {
      if decision != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'decision'"))
      }
      decision = $0
    }
    if let approve = try container.decodeIfPresent(ApproveDecision?.self, forKey: .approve) {
      try decisionCheckAndSet(.approve(approve))
    }
    if let dismiss = try container.decodeIfPresent(DismissDecision?.self, forKey: .dismiss) {
      try decisionCheckAndSet(.dismiss(dismiss))
    }
    self.decision = decision
  }

  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.requestedResourceName, forKey: .requestedResourceName)
    try container.encode(self.requestedResourceProperties, forKey: .requestedResourceProperties)
    try container.encode(self.requestedReason, forKey: .requestedReason)
    try container.encode(self.requestedLocations, forKey: .requestedLocations)
    try container.encode(self.requestTime, forKey: .requestTime)
    try container.encode(self.requestedExpiration, forKey: .requestedExpiration)

    if let choice = self.decision {
      switch choice {
      case .approve(let value):
        try container.encode(value, forKey: .approve)
      case .dismiss(let value):
        try container.encode(value, forKey: .dismiss)
      }
    }
  }

  /// The current decision on the approval request.
  public enum OneOf_Decision: Codable, Equatable, Sendable {
    /// Access was approved.
    indirect case approve(ApproveDecision?)
    /// The request was dismissed.
    indirect case dismiss(DismissDecision?)
  }

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