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

defmodule Ory.Api.Events do
  @moduledoc """
  API calls for all endpoints tagged `Events`.
  """

  alias Ory.Connection
  import Ory.RequestBuilder

  @doc """
  Create an event stream for your project.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `project_id` (String.t): Project ID  The project's ID.
  - `create_event_stream_body` (CreateEventStreamBody): 
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, Ory.Model.EventStream.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec create_event_stream(Tesla.Env.client, String.t, Ory.Model.CreateEventStreamBody.t, keyword()) :: {:ok, Ory.Model.ErrorGeneric.t} | {:ok, Ory.Model.EventStream.t} | {:error, Tesla.Env.t}
  def create_event_stream(connection, project_id, create_event_stream_body, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/projects/#{project_id}/eventstreams")
      |> add_param(:body, :body, create_event_stream_body)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {201, Ory.Model.EventStream},
      {400, Ory.Model.ErrorGeneric},
      {403, Ory.Model.ErrorGeneric},
      {409, Ory.Model.ErrorGeneric},
      {:default, Ory.Model.ErrorGeneric}
    ])
  end

  @doc """
  Remove an event stream from a project
  Remove an event stream from a project.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `project_id` (String.t): Project ID  The project's ID.
  - `event_stream_id` (String.t): Event Stream ID  The ID of the event stream to be deleted, as returned when created.
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, nil}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec delete_event_stream(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, nil} | {:ok, Ory.Model.ErrorGeneric.t} | {:error, Tesla.Env.t}
  def delete_event_stream(connection, project_id, event_stream_id, _opts \\ []) do
    request =
      %{}
      |> method(:delete)
      |> url("/projects/#{project_id}/eventstreams/#{event_stream_id}")
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {204, false},
      {400, Ory.Model.ErrorGeneric},
      {403, Ory.Model.ErrorGeneric},
      {409, Ory.Model.ErrorGeneric},
      {:default, Ory.Model.ErrorGeneric}
    ])
  end

  @doc """
  List all event streams for the project. This endpoint is not paginated.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `project_id` (String.t): Project ID  The project's ID.
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, Ory.Model.ListEventStreams.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec list_event_streams(Tesla.Env.client, String.t, keyword()) :: {:ok, Ory.Model.ErrorGeneric.t} | {:ok, Ory.Model.ListEventStreams.t} | {:error, Tesla.Env.t}
  def list_event_streams(connection, project_id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/projects/#{project_id}/eventstreams")
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Ory.Model.ListEventStreams},
      {400, Ory.Model.ErrorGeneric},
      {403, Ory.Model.ErrorGeneric},
      {:default, Ory.Model.ErrorGeneric}
    ])
  end

  @doc """
  Update an event stream for a project.

  ### Parameters

  - `connection` (Ory.Connection): Connection to server
  - `project_id` (String.t): Project ID  The project's ID.
  - `event_stream_id` (String.t): Event Stream ID  The event stream's ID.
  - `opts` (keyword): Optional parameters
    - `:body` (SetEventStreamBody): 

  ### Returns

  - `{:ok, Ory.Model.EventStream.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec set_event_stream(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, Ory.Model.ErrorGeneric.t} | {:ok, Ory.Model.EventStream.t} | {:error, Tesla.Env.t}
  def set_event_stream(connection, project_id, event_stream_id, opts \\ []) do
    optional_params = %{
      :body => :body
    }

    request =
      %{}
      |> method(:put)
      |> url("/projects/#{project_id}/eventstreams/#{event_stream_id}")
      |> add_optional_params(optional_params, opts)
      |> ensure_body()
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Ory.Model.EventStream},
      {400, Ory.Model.ErrorGeneric},
      {403, Ory.Model.ErrorGeneric},
      {409, Ory.Model.ErrorGeneric},
      {:default, Ory.Model.ErrorGeneric}
    ])
  end
end
