lib/chat_kitty/api/threads.ex

# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
# https://openapi-generator.tech
# Do not edit the class manually.

defmodule ChatKitty.Api.Threads do
  @moduledoc """
  API calls for all endpoints tagged `Threads`.
  """

  alias ChatKitty.Connection
  import ChatKitty.RequestBuilder


  @doc """
  List reply thread messages
  Returns a page of replies sent in this thread

  ## Parameters

  - connection (ChatKitty.Connection): Connection to server
  - id (integer()): 
  - opts (KeywordList): [optional] Optional parameters
    - :size (integer()): The size of the page to be returned
    - :start (integer()): Start cursor value. Do not set manually. Provided by the Platform API pagination engine to fetch previous or next pages
    - :next (integer()): Next page cursor value. Do not set manually. Provided by the Platform API pagination engine to fetch subsequent pages
    - :relation (String.t): Page cursor relation. Do not set manually. Provided by the Platform API pagination engine to fetch previous or next pages
  ## Returns

  {:ok, ChatKitty.Model.CursorPagedModelMessageResource.t} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec list_thread_messages(Tesla.Env.client, integer(), keyword()) :: {:ok, ChatKitty.Model.ApiError.t} | {:ok, ChatKitty.Model.CursorPagedModelMessageResource.t} | {:ok, ChatKitty.Model.AuthenticationError.t} | {:error, Tesla.Env.t}
  def list_thread_messages(connection, id, opts \\ []) do
    optional_params = %{
      :"size" => :query,
      :"start" => :query,
      :"next" => :query,
      :"relation" => :query
    }
    %{}
    |> method(:get)
    |> url("/v1/threads/#{id}/messages")
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 403, %ChatKitty.Model.AuthenticationError{}},
      { 400, %ChatKitty.Model.ApiError{}},
      { 401, %ChatKitty.Model.AuthenticationError{}},
      { 404, %ChatKitty.Model.ApiError{}},
      { 200, %ChatKitty.Model.CursorPagedModelMessageResource{}}
    ])
  end

  @doc """
  Retrieve a thread
  Returns a thread by ID

  ## Parameters

  - connection (ChatKitty.Connection): Connection to server
  - id (integer()): Reply thread ID
  - opts (KeywordList): [optional] Optional parameters
  ## Returns

  {:ok, ChatKitty.Model.ReplyThreadResource.t} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec retrieve_thread(Tesla.Env.client, integer(), keyword()) :: {:ok, ChatKitty.Model.ApiError.t} | {:ok, ChatKitty.Model.AuthenticationError.t} | {:ok, ChatKitty.Model.ReplyThreadResource.t} | {:error, Tesla.Env.t}
  def retrieve_thread(connection, id, _opts \\ []) do
    %{}
    |> method(:get)
    |> url("/v1/threads/#{id}")
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 403, %ChatKitty.Model.AuthenticationError{}},
      { 400, %ChatKitty.Model.ApiError{}},
      { 401, %ChatKitty.Model.AuthenticationError{}},
      { 404, %ChatKitty.Model.ApiError{}},
      { 200, %ChatKitty.Model.ReplyThreadResource{}}
    ])
  end

  @doc """
  Send a reply thread message
  Sends a reply message in this thread as the system or on behalf of a user

  ## Parameters

  - connection (ChatKitty.Connection): Connection to server
  - id (integer()): 
  - send_channel_message_request (SendChannelMessageRequest): 
  - opts (KeywordList): [optional] Optional parameters
  ## Returns

  {:ok, ChatKitty.Model.MessageResource.t} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec send_thread_message(Tesla.Env.client, integer(), ChatKitty.Model.SendChannelMessageRequest.t, keyword()) :: {:ok, ChatKitty.Model.ApiError.t} | {:ok, ChatKitty.Model.MessageResource.t} | {:ok, ChatKitty.Model.AuthenticationError.t} | {:error, Tesla.Env.t}
  def send_thread_message(connection, id, send_channel_message_request, _opts \\ []) do
    %{}
    |> method(:post)
    |> url("/v1/threads/#{id}/messages")
    |> add_param(:body, :body, send_channel_message_request)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 403, %ChatKitty.Model.AuthenticationError{}},
      { 400, %ChatKitty.Model.ApiError{}},
      { 401, %ChatKitty.Model.AuthenticationError{}},
      { 404, %ChatKitty.Model.ApiError{}},
      { 200, %ChatKitty.Model.MessageResource{}}
    ])
  end
end