// 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 entry for an Access Control list.
public struct SqlAclEntry: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// The allowlisted value for the access control list.
  public var value: Swift.String = Swift.String()

  /// A label to identify this entry.
  public var label: Swift.String = Swift.String()

  /// The access control entry entry expiration.
  public var expiration: OneOf_Expiration? = nil

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

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

    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.value, forKey: .value)
    try container.encode(self.label, forKey: .label)

    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)
      }
    }
  }

  /// The access control entry entry expiration.
  public enum OneOf_Expiration: Codable, Equatable, Sendable {
    /// The time when this access control entry expires in
    /// [RFC 3339](https://tools.ietf.org/html/rfc3339) format, for example:
    /// `2012-11-15T16:19:00.094Z`.
    indirect case expireTime(GoogleCloudWkt.Timestamp?)
    /// Input only. The time-to-leave of this access control entry.
    indirect case ttl(GoogleCloudWkt.Duration?)
  }

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