defmodule {{ conn_module }} do
  @moduledoc """
  HTTP request context passed to handlers.

  Contains path parameters, query parameters, headers, cookies, and body data.
  Handlers receive this struct as the single argument and use it to access request data.
  """

  defstruct [
    :path_params,
    :query_params,
    :headers,
    :cookies,
    :body,
    :raw_body,
    :method,
    :path
  ]

  @typedoc """
  HTTP request context.

  Fields:
  - path_params: Map of path parameters extracted from the URL
  - query_params: Map of query parameters
  - headers: Map of HTTP headers
  - cookies: Map of HTTP cookies
  - body: Parsed request body (JSON or other format)
  - raw_body: Raw request body bytes
  - method: HTTP method (GET, POST, etc.)
  - path: Request path
  """
  @type t :: %__MODULE__{
    path_params: map(),
    query_params: map(),
    headers: map(),
    cookies: map(),
    body: any(),
    raw_body: binary() | nil,
    method: String.t(),
    path: String.t()
  }

  @doc """
  Get a path parameter value.
  """
  def path_param(%__MODULE__{path_params: params}, name) when is_binary(name) do
    Map.get(params, name)
  end

  @doc """
  Get a query parameter value.
  """
  def query_param(%__MODULE__{query_params: params}, name) when is_binary(name) do
    Map.get(params, name)
  end

  @doc """
  Get a header value.
  """
  def header(%__MODULE__{headers: headers}, name) when is_binary(name) do
    Map.get(headers, name)
  end

  @doc """
  Get a cookie value.
  """
  def cookie(%__MODULE__{cookies: cookies}, name) when is_binary(name) do
    Map.get(cookies, name)
  end
end
