lib/mail_slurp_api/api/wait_for_controller.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 MailSlurpAPI.Api.WaitForController do
  @moduledoc """
  API calls for all endpoints tagged `WaitForController`.
  """

  alias MailSlurpAPI.Connection
  import MailSlurpAPI.RequestBuilder


  @doc """
  Wait for an email to match the provided filter conditions such as subject contains keyword.
  Generic waitFor method that will wait until an inbox meets given conditions or return immediately if already met

  ## Parameters

  - connection (MailSlurpAPI.Connection): Connection to server
  - wait_for_conditions (WaitForConditions): 
  - opts (KeywordList): [optional] Optional parameters
  ## Returns

  {:ok, [%EmailPreview{}, ...]} on success
  {:error, info} on failure
  """
  @spec wait_for(Tesla.Env.client, MailSlurpAPI.Model.WaitForConditions.t, keyword()) :: {:ok, list(MailSlurpAPI.Model.EmailPreview.t)} | {:error, Tesla.Env.t}
  def wait_for(connection, wait_for_conditions, _opts \\ []) do
    %{}
    |> method(:post)
    |> url("/waitFor")
    |> add_param(:body, :body, wait_for_conditions)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 200, [%MailSlurpAPI.Model.EmailPreview{}]}
    ])
  end

  @doc """
  Wait for and return count number of emails. Hold connection until inbox count matches expected or timeout occurs
  If inbox contains count or more emails at time of request then return count worth of emails. If not wait until the count is reached and return those or return an error if timeout is exceeded.

  ## Parameters

  - connection (MailSlurpAPI.Connection): Connection to server
  - inbox_id (String.t): Id of the inbox we are fetching emails from
  - count (integer()): Number of emails to wait for. Must be greater that 1
  - opts (KeywordList): [optional] Optional parameters
    - :timeout (integer()): Max milliseconds to wait
    - :unread_only (boolean()): Optional filter for unread only
    - :before (DateTime.t): Filter for emails that were received before the given timestamp
    - :since (DateTime.t): Filter for emails that were received after the given timestamp
    - :sort (String.t): Sort direction
    - :delay (integer()): Max milliseconds delay between calls
  ## Returns

  {:ok, [%EmailPreview{}, ...]} on success
  {:error, info} on failure
  """
  @spec wait_for_email_count(Tesla.Env.client, String.t, integer(), keyword()) :: {:ok, list(MailSlurpAPI.Model.EmailPreview.t)} | {:error, Tesla.Env.t}
  def wait_for_email_count(connection, inbox_id, count, opts \\ []) do
    optional_params = %{
      :"timeout" => :query,
      :"unreadOnly" => :query,
      :"before" => :query,
      :"since" => :query,
      :"sort" => :query,
      :"delay" => :query
    }
    %{}
    |> method(:get)
    |> url("/waitForEmailCount")
    |> add_param(:query, :"inboxId", inbox_id)
    |> add_param(:query, :"count", count)
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 200, [%MailSlurpAPI.Model.EmailPreview{}]}
    ])
  end

  @doc """
  Fetch inbox's latest email or if empty wait for an email to arrive
  Will return either the last received email or wait for an email to arrive and return that. If you need to wait for an email for a non-empty inbox set `unreadOnly=true` or see the other receive methods such as `waitForNthEmail` or `waitForEmailCount`.

  ## Parameters

  - connection (MailSlurpAPI.Connection): Connection to server
  - opts (KeywordList): [optional] Optional parameters
    - :inbox_id (String.t): Id of the inbox we are fetching emails from
    - :timeout (integer()): Max milliseconds to wait
    - :unread_only (boolean()): Optional filter for unread only.
    - :before (DateTime.t): Filter for emails that were before after the given timestamp
    - :since (DateTime.t): Filter for emails that were received after the given timestamp
    - :sort (String.t): Sort direction
    - :delay (integer()): Max milliseconds delay between calls
  ## Returns

  {:ok, %MailSlurpAPI.Model.Email{}} on success
  {:error, info} on failure
  """
  @spec wait_for_latest_email(Tesla.Env.client, keyword()) :: {:ok, MailSlurpAPI.Model.Email.t} | {:error, Tesla.Env.t}
  def wait_for_latest_email(connection, opts \\ []) do
    optional_params = %{
      :"inboxId" => :query,
      :"timeout" => :query,
      :"unreadOnly" => :query,
      :"before" => :query,
      :"since" => :query,
      :"sort" => :query,
      :"delay" => :query
    }
    %{}
    |> method(:get)
    |> url("/waitForLatestEmail")
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 200, %MailSlurpAPI.Model.Email{}}
    ])
  end

  @doc """
  Wait for the latest SMS message to match the provided filter conditions such as body contains keyword.
  Wait until a phone number meets given conditions or return immediately if already met

  ## Parameters

  - connection (MailSlurpAPI.Connection): Connection to server
  - wait_for_single_sms_options (WaitForSingleSmsOptions): 
  - opts (KeywordList): [optional] Optional parameters
  ## Returns

  {:ok, %MailSlurpAPI.Model.SmsDto{}} on success
  {:error, info} on failure
  """
  @spec wait_for_latest_sms(Tesla.Env.client, MailSlurpAPI.Model.WaitForSingleSmsOptions.t, keyword()) :: {:ok, MailSlurpAPI.Model.SmsDto.t} | {:error, Tesla.Env.t}
  def wait_for_latest_sms(connection, wait_for_single_sms_options, _opts \\ []) do
    %{}
    |> method(:post)
    |> url("/waitForLatestSms")
    |> add_param(:body, :body, wait_for_single_sms_options)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 200, %MailSlurpAPI.Model.SmsDto{}}
    ])
  end

  @doc """
  Wait or return list of emails that match simple matching patterns
  Perform a search of emails in an inbox with the given patterns. If results match expected count then return or else retry the search until results are found or timeout is reached. Match options allow simple CONTAINS or EQUALS filtering on SUBJECT, TO, BCC, CC, and FROM. See the `MatchOptions` object for options. An example payload is `{ matches: [{field: 'SUBJECT',should:'CONTAIN',value:'needle'}] }`. You can use an array of matches and they will be applied sequentially to filter out emails. If you want to perform matches and extractions of content using Regex patterns see the EmailController `getEmailContentMatch` method.

  ## Parameters

  - connection (MailSlurpAPI.Connection): Connection to server
  - inbox_id (String.t): Id of the inbox we are fetching emails from
  - count (integer()): Number of emails to wait for. Must be greater or equal to 1
  - match_options (MatchOptions): 
  - opts (KeywordList): [optional] Optional parameters
    - :before (DateTime.t): Filter for emails that were received before the given timestamp
    - :since (DateTime.t): Filter for emails that were received after the given timestamp
    - :sort (String.t): Sort direction
    - :delay (integer()): Max milliseconds delay between calls
    - :timeout (integer()): Max milliseconds to wait
    - :unread_only (boolean()): Optional filter for unread only
  ## Returns

  {:ok, [%EmailPreview{}, ...]} on success
  {:error, info} on failure
  """
  @spec wait_for_matching_emails(Tesla.Env.client, String.t, integer(), MailSlurpAPI.Model.MatchOptions.t, keyword()) :: {:ok, list(MailSlurpAPI.Model.EmailPreview.t)} | {:error, Tesla.Env.t}
  def wait_for_matching_emails(connection, inbox_id, count, match_options, opts \\ []) do
    optional_params = %{
      :"before" => :query,
      :"since" => :query,
      :"sort" => :query,
      :"delay" => :query,
      :"timeout" => :query,
      :"unreadOnly" => :query
    }
    %{}
    |> method(:post)
    |> url("/waitForMatchingEmails")
    |> add_param(:query, :"inboxId", inbox_id)
    |> add_param(:query, :"count", count)
    |> add_param(:body, :body, match_options)
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 200, [%MailSlurpAPI.Model.EmailPreview{}]}
    ])
  end

  @doc """
  Wait for or return the first email that matches provided MatchOptions array
  Perform a search of emails in an inbox with the given patterns. If a result if found then return or else retry the search until a result is found or timeout is reached. Match options allow simple CONTAINS or EQUALS filtering on SUBJECT, TO, BCC, CC, and FROM. See the `MatchOptions` object for options. An example payload is `{ matches: [{field: 'SUBJECT',should:'CONTAIN',value:'needle'}] }`. You can use an array of matches and they will be applied sequentially to filter out emails. If you want to perform matches and extractions of content using Regex patterns see the EmailController `getEmailContentMatch` method.

  ## Parameters

  - connection (MailSlurpAPI.Connection): Connection to server
  - inbox_id (String.t): Id of the inbox we are matching an email for
  - match_options (MatchOptions): 
  - opts (KeywordList): [optional] Optional parameters
    - :timeout (integer()): Max milliseconds to wait
    - :unread_only (boolean()): Optional filter for unread only
    - :since (DateTime.t): Filter for emails that were received after the given timestamp
    - :before (DateTime.t): Filter for emails that were received before the given timestamp
    - :sort (String.t): Sort direction
    - :delay (integer()): Max milliseconds delay between calls
  ## Returns

  {:ok, %MailSlurpAPI.Model.Email{}} on success
  {:error, info} on failure
  """
  @spec wait_for_matching_first_email(Tesla.Env.client, String.t, MailSlurpAPI.Model.MatchOptions.t, keyword()) :: {:ok, MailSlurpAPI.Model.Email.t} | {:error, Tesla.Env.t}
  def wait_for_matching_first_email(connection, inbox_id, match_options, opts \\ []) do
    optional_params = %{
      :"timeout" => :query,
      :"unreadOnly" => :query,
      :"since" => :query,
      :"before" => :query,
      :"sort" => :query,
      :"delay" => :query
    }
    %{}
    |> method(:post)
    |> url("/waitForMatchingFirstEmail")
    |> add_param(:query, :"inboxId", inbox_id)
    |> add_param(:body, :body, match_options)
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 200, %MailSlurpAPI.Model.Email{}}
    ])
  end

  @doc """
  Wait for or fetch the email with a given index in the inbox specified. If index doesn't exist waits for it to exist or timeout to occur.
  If nth email is already present in inbox then return it. If not hold the connection open until timeout expires or the nth email is received and returned.

  ## Parameters

  - connection (MailSlurpAPI.Connection): Connection to server
  - opts (KeywordList): [optional] Optional parameters
    - :inbox_id (String.t): Id of the inbox you are fetching emails from
    - :index (integer()): Zero based index of the email to wait for. If an inbox has 1 email already and you want to wait for the 2nd email pass index=1
    - :timeout (integer()): Max milliseconds to wait for the nth email if not already present
    - :unread_only (boolean()): Optional filter for unread only
    - :since (DateTime.t): Filter for emails that were received after the given timestamp
    - :before (DateTime.t): Filter for emails that were received before the given timestamp
    - :sort (String.t): Sort direction
    - :delay (integer()): Max milliseconds delay between calls
  ## Returns

  {:ok, %MailSlurpAPI.Model.Email{}} on success
  {:error, info} on failure
  """
  @spec wait_for_nth_email(Tesla.Env.client, keyword()) :: {:ok, MailSlurpAPI.Model.Email.t} | {:error, Tesla.Env.t}
  def wait_for_nth_email(connection, opts \\ []) do
    optional_params = %{
      :"inboxId" => :query,
      :"index" => :query,
      :"timeout" => :query,
      :"unreadOnly" => :query,
      :"since" => :query,
      :"before" => :query,
      :"sort" => :query,
      :"delay" => :query
    }
    %{}
    |> method(:get)
    |> url("/waitForNthEmail")
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 200, %MailSlurpAPI.Model.Email{}}
    ])
  end

  @doc """
  Wait for an SMS message to match the provided filter conditions such as body contains keyword.
  Generic waitFor method that will wait until a phone number meets given conditions or return immediately if already met

  ## Parameters

  - connection (MailSlurpAPI.Connection): Connection to server
  - wait_for_sms_conditions (WaitForSmsConditions): 
  - opts (KeywordList): [optional] Optional parameters
  ## Returns

  {:ok, [%SmsPreview{}, ...]} on success
  {:error, info} on failure
  """
  @spec wait_for_sms(Tesla.Env.client, MailSlurpAPI.Model.WaitForSmsConditions.t, keyword()) :: {:ok, list(MailSlurpAPI.Model.SmsPreview.t)} | {:error, Tesla.Env.t}
  def wait_for_sms(connection, wait_for_sms_conditions, _opts \\ []) do
    %{}
    |> method(:post)
    |> url("/waitForSms")
    |> add_param(:body, :body, wait_for_sms_conditions)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      { 200, [%MailSlurpAPI.Model.SmsPreview{}]}
    ])
  end
end