// 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
/// [KeyManagementService.Decrypt][google.cloud.kms.v1.KeyManagementService.Decrypt].
///
/// [google.cloud.kms.v1.KeyManagementService.Decrypt]: <doc:KeyManagementService/decrypt(request:)>
public struct DecryptRequest: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Required. The resource name of the
  /// [CryptoKey][google.cloud.kms.v1.CryptoKey] to use for decryption. The
  /// server will choose the appropriate version.
  ///
  /// [google.cloud.kms.v1.CryptoKey]: <doc:CryptoKey>
  public var name: Swift.String = Swift.String()

  /// Required. The encrypted data originally returned in
  /// [EncryptResponse.ciphertext][google.cloud.kms.v1.EncryptResponse.ciphertext].
  ///
  /// [google.cloud.kms.v1.EncryptResponse.ciphertext]: <doc:EncryptResponse/ciphertext>
  public var ciphertext: Foundation.Data = Foundation.Data()

  /// Optional. Optional data that must match the data originally supplied in
  /// [EncryptRequest.additional_authenticated_data][google.cloud.kms.v1.EncryptRequest.additional_authenticated_data].
  ///
  /// [google.cloud.kms.v1.EncryptRequest.additional_authenticated_data]: <doc:EncryptRequest/additionalAuthenticatedData>
  public var additionalAuthenticatedData: Foundation.Data = Foundation.Data()

  /// Optional. An optional CRC32C checksum of the
  /// [DecryptRequest.ciphertext][google.cloud.kms.v1.DecryptRequest.ciphertext].
  /// If specified,
  /// [KeyManagementService][google.cloud.kms.v1.KeyManagementService] will
  /// verify the integrity of the received
  /// [DecryptRequest.ciphertext][google.cloud.kms.v1.DecryptRequest.ciphertext]
  /// using this checksum.
  /// [KeyManagementService][google.cloud.kms.v1.KeyManagementService] will
  /// report an error if the checksum verification fails. If you receive a
  /// checksum error, your client should verify that
  /// CRC32C([DecryptRequest.ciphertext][google.cloud.kms.v1.DecryptRequest.ciphertext])
  /// is equal to
  /// [DecryptRequest.ciphertext_crc32c][google.cloud.kms.v1.DecryptRequest.ciphertext_crc32c],
  /// and if so, perform a limited number of retries. A persistent mismatch may
  /// indicate an issue in your computation of the CRC32C checksum. Note: This
  /// field is defined as int64 for reasons of compatibility across different
  /// languages. However, it is a non-negative integer, which will never exceed
  /// 2^32-1, and can be safely downconverted to uint32 in languages that support
  /// this type.
  ///
  /// [google.cloud.kms.v1.DecryptRequest.ciphertext]: <doc:DecryptRequest/ciphertext>
  /// [google.cloud.kms.v1.DecryptRequest.ciphertext_crc32c]: <doc:DecryptRequest/ciphertextCrc32C>
  /// [google.cloud.kms.v1.KeyManagementService]: <doc:KeyManagementService>
  public var ciphertextCrc32C: GoogleCloudWkt.Int64Value? = nil

  /// Optional. An optional CRC32C checksum of the
  /// [DecryptRequest.additional_authenticated_data][google.cloud.kms.v1.DecryptRequest.additional_authenticated_data].
  /// If specified,
  /// [KeyManagementService][google.cloud.kms.v1.KeyManagementService] will
  /// verify the integrity of the received
  /// [DecryptRequest.additional_authenticated_data][google.cloud.kms.v1.DecryptRequest.additional_authenticated_data]
  /// using this checksum.
  /// [KeyManagementService][google.cloud.kms.v1.KeyManagementService] will
  /// report an error if the checksum verification fails. If you receive a
  /// checksum error, your client should verify that
  /// CRC32C([DecryptRequest.additional_authenticated_data][google.cloud.kms.v1.DecryptRequest.additional_authenticated_data])
  /// is equal to
  /// [DecryptRequest.additional_authenticated_data_crc32c][google.cloud.kms.v1.DecryptRequest.additional_authenticated_data_crc32c],
  /// and if so, perform a limited number of retries. A persistent mismatch may
  /// indicate an issue in your computation of the CRC32C checksum. Note: This
  /// field is defined as int64 for reasons of compatibility across different
  /// languages. However, it is a non-negative integer, which will never exceed
  /// 2^32-1, and can be safely downconverted to uint32 in languages that support
  /// this type.
  ///
  /// [google.cloud.kms.v1.DecryptRequest.additional_authenticated_data]: <doc:DecryptRequest/additionalAuthenticatedData>
  /// [google.cloud.kms.v1.DecryptRequest.additional_authenticated_data_crc32c]: <doc:DecryptRequest/additionalAuthenticatedDataCrc32C>
  /// [google.cloud.kms.v1.KeyManagementService]: <doc:KeyManagementService>
  public var additionalAuthenticatedDataCrc32C: GoogleCloudWkt.Int64Value? = nil

  /// Initialize a new instance of `DecryptRequest`.
  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 = DecryptRequest().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 ciphertext = "ciphertext"
    case additionalAuthenticatedData = "additionalAuthenticatedData"
    case ciphertextCrc32C = "ciphertextCrc32c"
    case additionalAuthenticatedDataCrc32C = "additionalAuthenticatedDataCrc32c"
  }

  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.ciphertext = try container.decode(Foundation.Data.self, forKey: .ciphertext)
    self.additionalAuthenticatedData = try container.decode(
      Foundation.Data.self, forKey: .additionalAuthenticatedData)
    self.ciphertextCrc32C = try container.decodeIfPresent(
      GoogleCloudWkt.Int64Value.self, forKey: .ciphertextCrc32C)
    self.additionalAuthenticatedDataCrc32C = try container.decodeIfPresent(
      GoogleCloudWkt.Int64Value.self, forKey: .additionalAuthenticatedDataCrc32C)
  }

  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.ciphertext, forKey: .ciphertext)
    try container.encode(self.additionalAuthenticatedData, forKey: .additionalAuthenticatedData)
    try container.encode(self.ciphertextCrc32C, forKey: .ciphertextCrc32C)
    try container.encode(
      self.additionalAuthenticatedDataCrc32C, forKey: .additionalAuthenticatedDataCrc32C)
  }

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