// 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 HTTP-based API Operation, sometimes called a "REST" Operation.
public struct HttpOperationDetails: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Required. An HTTP Operation.
  public var httpOperation: HttpOperation? = nil

  /// Optional. Path params of HttpOperation
  public var pathParams: [HttpOperationDetails.PathParam] = []

  /// Optional. Query params of HttpOperation
  public var queryParams: [Swift.String: HttpOperationDetails.QueryParam] = [:]

  /// Optional. Request metadata.
  public var request: HttpOperationDetails.HttpRequest? = nil

  /// Optional. Response metadata.
  public var response: HttpOperationDetails.HttpResponse? = nil

  /// Initialize a new instance of `HttpOperationDetails`.
  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 = HttpOperationDetails().with { $0.httpOperation = ... }
  /// ```
  public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
    var copy = self
    try config(&copy)
    return copy
  }

  /// HTTP Path parameter.
  public struct PathParam: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. Segment location in the path, 1-indexed
    public var position: Swift.Int32 = Swift.Int32()

    /// Optional. Data type of path param
    public var dataType: HttpOperationDetails.DataType = HttpOperationDetails.DataType()

    /// Initialize a new instance of `PathParam`.
    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 = PathParam().with { $0.position = ... }
    /// ```
    public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
      var copy = self
      try config(&copy)
      return copy
    }

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

  /// An aggregation of HTTP query parameter occurrences.
  public struct QueryParam: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Required. Name of query param
    public var name: Swift.String = Swift.String()

    /// Optional. The number of occurrences of this query parameter across
    /// transactions.
    public var count: Swift.Int64 = Swift.Int64()

    /// Optional. Data type of path param
    public var dataType: HttpOperationDetails.DataType = HttpOperationDetails.DataType()

    /// Initialize a new instance of `QueryParam`.
    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 = QueryParam().with { $0.name = ... }
    /// ```
    public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
      var copy = self
      try config(&copy)
      return copy
    }

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

  /// An aggregation of HTTP header occurrences.
  public struct Header: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Header name.
    public var name: Swift.String = Swift.String()

    /// The number of occurrences of this Header across transactions.
    public var count: Swift.Int64 = Swift.Int64()

    /// Data type of header
    public var dataType: HttpOperationDetails.DataType = HttpOperationDetails.DataType()

    /// Initialize a new instance of `Header`.
    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 = Header().with { $0.name = ... }
    /// ```
    public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
      var copy = self
      try config(&copy)
      return copy
    }

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

  /// An aggregation of HTTP requests.
  public struct HttpRequest: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. Unordered map from header name to header metadata
    public var headers: [Swift.String: HttpOperationDetails.Header] = [:]

    /// Initialize a new instance of `HttpRequest`.
    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 = HttpRequest().with { $0.headers = ... }
    /// ```
    public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
      var copy = self
      try config(&copy)
      return copy
    }

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

  /// An aggregation of HTTP responses.
  public struct HttpResponse: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. Unordered map from header name to header metadata
    public var headers: [Swift.String: HttpOperationDetails.Header] = [:]

    /// Optional. Map of status code to observed count
    public var responseCodes: [Swift.Int32: Swift.Int64] = [:]

    /// Initialize a new instance of `HttpResponse`.
    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 = HttpResponse().with { $0.headers = ... }
    /// ```
    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 headers = "headers"
      case responseCodes = "responseCodes"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)
      self.headers = try container.decode(
        [Swift.String: HttpOperationDetails.Header].self, forKey: .headers)
      self.responseCodes = try { () throws in
        let stringKeyed = try container.decode(
          [Swift.String: Swift.Int64].self, forKey: .responseCodes)
        let tuples = try stringKeyed.lazy.map { (key, value) throws -> (Swift.Int32, Swift.Int64) in
          guard let newKey = Swift.Int32(key) else {
            throw DecodingError.typeMismatch(
              Swift.Int32.self,
              DecodingError.Context(
                codingPath: decoder.codingPath,
                debugDescription: "Incorrect type for map key 'responseCodes'"))
          }
          return (newKey, value)
        }
        return Dictionary(uniqueKeysWithValues: tuples)
      }()
    }

    public func encode(to encoder: Encoder) throws {
      var container = encoder.container(keyedBy: CodingKeys.self)
      try container.encode(self.headers, forKey: .headers)
      do {
        let stringKeyed = Dictionary(
          uniqueKeysWithValues: self.responseCodes.lazy.map { (Swift.String($0), $1) }
        )
        try container.encode(stringKeyed, forKey: .responseCodes)
      }
    }

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

  /// Type of data
  public enum DataType: Codable, Equatable, Sendable {
    /// Unspecified data type
    case unspecified
    /// Boolean data type
    case bool
    /// Integer data type
    case integer
    /// Float data type
    case float
    /// String data type
    case string
    /// UUID data type
    case uuid
    /// Encodes an unknown integer value.
    ///
    /// The most common cause for an unknown values is for the service to send
    /// a value unknown to the library. We recommend you update your library to
    /// the latest version.
    case unknownIntValue(Int)
    /// Encodes an unknown string value.
    ///
    /// The most common cause for an unknown values is for the service to send
    /// a value unknown to the library. We recommend you update your library to
    /// the latest version.
    case unknownStringValue(String)

    public init() {
      self = .unspecified
    }

    /// Returns the integer value associated with the enumeration.
    ///
    /// If the enumeration was initialized with an unknown string value, this returns `nil`.
    public var intValue: Int? {
      switch self {
      case .unspecified: return 0
      case .bool: return 1
      case .integer: return 2
      case .float: return 3
      case .string: return 4
      case .uuid: return 5
      case .unknownIntValue(let v): return v
      case .unknownStringValue: return nil
      }
    }

    /// Returns the string value (or name) associated with the enumeration.
    ///
    /// If the enumeration was initialized with an unknown integer value, this returns `nil`.
    public var stringValue: Swift.String? {
      switch self {
      case .unspecified: return "DATA_TYPE_UNSPECIFIED"
      case .bool: return "BOOL"
      case .integer: return "INTEGER"
      case .float: return "FLOAT"
      case .string: return "STRING"
      case .uuid: return "UUID"
      case .unknownIntValue: return nil
      case .unknownStringValue(let v): return v
      }
    }

    /// Initialize from a string value.
    ///
    /// If the value is unknown, this initializes to [`unknownStringValue`](doc:DataType/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "DATA_TYPE_UNSPECIFIED": self = .unspecified
      case "BOOL": self = .bool
      case "INTEGER": self = .integer
      case "FLOAT": self = .float
      case "STRING": self = .string
      case "UUID": self = .uuid
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:DataType/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .bool
      case 2: self = .integer
      case 3: self = .float
      case 4: self = .string
      case 5: self = .uuid
      default: self = .unknownIntValue(intValue)
      }
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.singleValueContainer()
      if let v = try? container.decode(Int.self) {
        self.init(intValue: v)
        return
      }
      if let s = try? container.decode(String.self) {
        if let v = Int(s) {
          self.init(intValue: v)
        } else {
          self.init(stringValue: s)
        }
        return
      }
      throw DecodingError.dataCorruptedError(
        in: container, debugDescription: "Expected enum value, must be integer or string.")
    }

    public func encode(to encoder: Encoder) throws {
      var container = encoder.singleValueContainer()
      switch self {
      case .unspecified: return try container.encode(0)
      case .bool: return try container.encode(1)
      case .integer: return try container.encode(2)
      case .float: return try container.encode(3)
      case .string: return try container.encode(4)
      case .uuid: return try container.encode(5)
      case .unknownIntValue(let v): return try container.encode(v)
      case .unknownStringValue(let v): return try container.encode(v)
      }
    }
  }

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