// 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 common proto for logging HTTP requests. Only contains semantics
/// defined by the HTTP specification. Product-specific logging
/// information MUST be defined in a separate message.
public struct HttpRequest: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// The request method. Examples: `"GET"`, `"HEAD"`, `"PUT"`, `"POST"`.
  public var requestMethod: Swift.String = Swift.String()

  /// The scheme (http, https), the host name, the path, and the query
  /// portion of the URL that was requested.
  /// Example: `"http://example.com/some/info?color=red"`.
  public var requestUrl: Swift.String = Swift.String()

  /// The size of the HTTP request message in bytes, including the request
  /// headers and the request body.
  public var requestSize: Swift.Int64 = Swift.Int64()

  /// The response code indicating the status of the response.
  /// Examples: 200, 404.
  public var status: Swift.Int32 = Swift.Int32()

  /// The size of the HTTP response message sent back to the client, in bytes,
  /// including the response headers and the response body.
  public var responseSize: Swift.Int64 = Swift.Int64()

  /// The user agent sent by the client. Example:
  /// `"Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Q312461; .NET
  /// CLR 1.0.3705)"`.
  public var userAgent: Swift.String = Swift.String()

  /// The IP address (IPv4 or IPv6) of the client that issued the HTTP
  /// request. Examples: `"192.168.1.1"`, `"FE80::0202:B3FF:FE1E:8329"`.
  public var remoteIp: Swift.String = Swift.String()

  /// The IP address (IPv4 or IPv6) of the origin server that the request was
  /// sent to.
  public var serverIp: Swift.String = Swift.String()

  /// The referer URL of the request, as defined in
  /// [HTTP/1.1 Header Field
  /// Definitions](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html).
  public var referer: Swift.String = Swift.String()

  /// The request processing latency on the server, from the time the request was
  /// received until the response was sent.
  public var latency: GoogleCloudWkt.Duration? = nil

  /// Whether or not a cache lookup was attempted.
  public var cacheLookup: Swift.Bool = Swift.Bool()

  /// Whether or not an entity was served from cache
  /// (with or without validation).
  public var cacheHit: Swift.Bool = Swift.Bool()

  /// Whether or not the response was validated with the origin server before
  /// being served from cache. This field is only meaningful if `cache_hit` is
  /// True.
  public var cacheValidatedWithOriginServer: Swift.Bool = Swift.Bool()

  /// The number of HTTP response bytes inserted into cache. Set only when a
  /// cache fill was attempted.
  public var cacheFillBytes: Swift.Int64 = Swift.Int64()

  /// Protocol used for the request. Examples: "HTTP/1.1", "HTTP/2", "websocket"
  public var `protocol`: Swift.String = Swift.String()

  /// 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.requestMethod = ... }
  /// ```
  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 requestMethod = "requestMethod"
    case requestUrl = "requestUrl"
    case requestSize = "requestSize"
    case status = "status"
    case responseSize = "responseSize"
    case userAgent = "userAgent"
    case remoteIp = "remoteIp"
    case serverIp = "serverIp"
    case referer = "referer"
    case latency = "latency"
    case cacheLookup = "cacheLookup"
    case cacheHit = "cacheHit"
    case cacheValidatedWithOriginServer = "cacheValidatedWithOriginServer"
    case cacheFillBytes = "cacheFillBytes"
    case `protocol` = "protocol"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.requestMethod = try container.decode(Swift.String.self, forKey: .requestMethod)
    self.requestUrl = try container.decode(Swift.String.self, forKey: .requestUrl)
    self.requestSize = try container.decode(Swift.Int64.self, forKey: .requestSize)
    self.status = try container.decode(Swift.Int32.self, forKey: .status)
    self.responseSize = try container.decode(Swift.Int64.self, forKey: .responseSize)
    self.userAgent = try container.decode(Swift.String.self, forKey: .userAgent)
    self.remoteIp = try container.decode(Swift.String.self, forKey: .remoteIp)
    self.serverIp = try container.decode(Swift.String.self, forKey: .serverIp)
    self.referer = try container.decode(Swift.String.self, forKey: .referer)
    self.latency = try container.decodeIfPresent(GoogleCloudWkt.Duration.self, forKey: .latency)
    self.cacheLookup = try container.decode(Swift.Bool.self, forKey: .cacheLookup)
    self.cacheHit = try container.decode(Swift.Bool.self, forKey: .cacheHit)
    self.cacheValidatedWithOriginServer = try container.decode(
      Swift.Bool.self, forKey: .cacheValidatedWithOriginServer)
    self.cacheFillBytes = try container.decode(Swift.Int64.self, forKey: .cacheFillBytes)
    self.`protocol` = try container.decode(Swift.String.self, forKey: .`protocol`)
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.requestMethod, forKey: .requestMethod)
    try container.encode(self.requestUrl, forKey: .requestUrl)
    try container.encode(self.requestSize, forKey: .requestSize)
    try container.encode(self.status, forKey: .status)
    try container.encode(self.responseSize, forKey: .responseSize)
    try container.encode(self.userAgent, forKey: .userAgent)
    try container.encode(self.remoteIp, forKey: .remoteIp)
    try container.encode(self.serverIp, forKey: .serverIp)
    try container.encode(self.referer, forKey: .referer)
    try container.encode(self.latency, forKey: .latency)
    try container.encode(self.cacheLookup, forKey: .cacheLookup)
    try container.encode(self.cacheHit, forKey: .cacheHit)
    try container.encode(
      self.cacheValidatedWithOriginServer, forKey: .cacheValidatedWithOriginServer)
    try container.encode(self.cacheFillBytes, forKey: .cacheFillBytes)
    try container.encode(self.`protocol`, forKey: .`protocol`)
  }

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