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

/// Metadata for long running Link operations.
public struct LinkMetadata: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// The start time of an operation.
  public var startTime: GoogleCloudWkt.Timestamp? = nil

  /// The end time of an operation.
  public var endTime: GoogleCloudWkt.Timestamp? = nil

  /// State of an operation.
  public var state: OperationState = OperationState()

  public var request: OneOf_Request? = nil

  /// Initialize a new instance of `LinkMetadata`.
  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 = LinkMetadata().with { $0.startTime = ... }
  /// ```
  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 startTime = "startTime"
    case endTime = "endTime"
    case state = "state"
    case createLinkRequest = "createLinkRequest"
    case deleteLinkRequest = "deleteLinkRequest"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.startTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .startTime)
    self.endTime = try container.decodeIfPresent(GoogleCloudWkt.Timestamp.self, forKey: .endTime)
    self.state = try container.decode(OperationState.self, forKey: .state)

    var request: OneOf_Request? = nil
    let requestCheckAndSet = {
      if request != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'request'"))
      }
      request = $0
    }
    if let createLinkRequest = try container.decodeIfPresent(
      CreateLinkRequest?.self, forKey: .createLinkRequest)
    {
      try requestCheckAndSet(.createLinkRequest(createLinkRequest))
    }
    if let deleteLinkRequest = try container.decodeIfPresent(
      DeleteLinkRequest?.self, forKey: .deleteLinkRequest)
    {
      try requestCheckAndSet(.deleteLinkRequest(deleteLinkRequest))
    }
    self.request = request
  }

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

    if let choice = self.request {
      switch choice {
      case .createLinkRequest(let value):
        try container.encode(value, forKey: .createLinkRequest)
      case .deleteLinkRequest(let value):
        try container.encode(value, forKey: .deleteLinkRequest)
      }
    }
  }

  public enum OneOf_Request: Codable, Equatable, Sendable {
    /// CreateLink RPC request.
    indirect case createLinkRequest(CreateLinkRequest?)
    /// DeleteLink RPC request.
    indirect case deleteLinkRequest(DeleteLinkRequest?)
  }

  public static var _anyTypeUrl: Swift.String {
    return "type.googleapis.com/google.logging.v2.LinkMetadata"
  }
  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)
  }
}
