lib/spatio/api/calendar.ex

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

defmodule Spatio.Api.Calendar do
  @moduledoc """
  API calls for all endpoints tagged `Calendar`.
  """

  alias Spatio.Connection
  import Spatio.RequestBuilder

  @doc """
  Create a calendar event.
  Single-account create. `account_id` is required (no auto-resolve for write operations). Reminder array is mirrored into native tasks under the hood; conference data is auto-attached when `conference_type` is supplied. 

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `create_event_request` (CreateEventRequest): 
  - `opts` (keyword): Optional parameters
    - `:"X-Workspace-ID"` (String.t): Workspace scope for unscoped tokens. Workspace-scoped PATs and OAuth tokens carry this implicitly; for session/JWT auth without a scoped PAT, pass it explicitly. 

  ### Returns

  - `{:ok, Spatio.Model.CreateCalendarEvent201Response.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec create_calendar_event(Tesla.Env.client, Spatio.Model.CreateEventRequest.t, keyword()) :: {:ok, Spatio.Model.CreateCalendarEvent201Response.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def create_calendar_event(connection, create_event_request, opts \\ []) do
    optional_params = %{
      :"X-Workspace-ID" => :headers
    }

    request =
      %{}
      |> method(:post)
      |> url("/v1/calendar/events")
      |> add_param(:body, :body, create_event_request)
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {201, Spatio.Model.CreateCalendarEvent201Response},
      {400, Spatio.Model.ApiError},
      {401, Spatio.Model.ApiError},
      {500, Spatio.Model.ApiError}
    ])
  end

  @doc """
  Delete an event.
  Hard delete (no soft-delete / trash). Cascades to any reminder tasks the platform created from this event. 

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `id` (String.t): Event id.
  - `account_id` (String.t): Connected-account id (snake_case in this platform — the rest of the SpatioAPI uses `accountId`). Required for single-event operations. 
  - `opts` (keyword): Optional parameters
    - `:"X-Workspace-ID"` (String.t): Workspace scope for unscoped tokens. Workspace-scoped PATs and OAuth tokens carry this implicitly; for session/JWT auth without a scoped PAT, pass it explicitly. 

  ### Returns

  - `{:ok, Spatio.Model.CalendarOperationResult.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec delete_calendar_event(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, Spatio.Model.CalendarOperationResult.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def delete_calendar_event(connection, id, account_id, opts \\ []) do
    optional_params = %{
      :"X-Workspace-ID" => :headers
    }

    request =
      %{}
      |> method(:delete)
      |> url("/v1/calendar/events/#{id}")
      |> add_param(:query, :account_id, account_id)
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Spatio.Model.CalendarOperationResult},
      {400, Spatio.Model.ApiError},
      {401, Spatio.Model.ApiError},
      {404, Spatio.Model.ApiError}
    ])
  end

  @doc """
  Per-account capability flags.
  Returns the capabilities the provider declares for the given connected account. The renderer uses these to enable/disable form fields (recurrence picker, attendee inputs, etc.). 

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `account_id` (String.t): Connected-account id (snake_case in this platform — the rest of the SpatioAPI uses `accountId`). Required for single-event operations. 
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, Spatio.Model.CalendarCapabilitiesResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec get_calendar_capabilities(Tesla.Env.client, String.t, keyword()) :: {:ok, Spatio.Model.CalendarCapabilitiesResponse.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def get_calendar_capabilities(connection, account_id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/calendar/capabilities")
      |> add_param(:query, :account_id, account_id)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Spatio.Model.CalendarCapabilitiesResponse},
      {400, Spatio.Model.ApiError},
      {401, Spatio.Model.ApiError},
      {404, Spatio.Model.ApiError}
    ])
  end

  @doc """
  Fetch one event.
  Requires `?account_id=` to identify the source account. Response is the bare `Event` (not wrapped in CalendarOperationResult — distinct from the list/create/update shapes). 

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `id` (String.t): Event id.
  - `account_id` (String.t): Connected-account id (snake_case in this platform — the rest of the SpatioAPI uses `accountId`). Required for single-event operations. 
  - `opts` (keyword): Optional parameters
    - `:"X-Workspace-ID"` (String.t): Workspace scope for unscoped tokens. Workspace-scoped PATs and OAuth tokens carry this implicitly; for session/JWT auth without a scoped PAT, pass it explicitly. 

  ### Returns

  - `{:ok, Spatio.Model.SpatioEvent.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec get_calendar_event(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, Spatio.Model.SpatioEvent.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def get_calendar_event(connection, id, account_id, opts \\ []) do
    optional_params = %{
      :"X-Workspace-ID" => :headers
    }

    request =
      %{}
      |> method(:get)
      |> url("/v1/calendar/events/#{id}")
      |> add_param(:query, :account_id, account_id)
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Spatio.Model.SpatioEvent},
      {400, Spatio.Model.ApiError},
      {401, Spatio.Model.ApiError},
      {404, Spatio.Model.ApiError}
    ])
  end

  @doc """
  List calendar events across connected accounts.
  Fan-out list. Returns events across every connected calendar provider unless filtered by `account_ids[]` or `providers[]`. Supports the cross-platform repeated-or-comma-separated filter syntax (`?account_ids=a&account_ids=b` or `?account_ids=a,b`).  Time bounds (`timeMin` / `timeMax`) accept both RFC3339 and RFC3339Nano. The handler also accepts the snake_case `time_min` / `time_max` for direct curl callers; the spec models the camelCase form because that's what the renderer and SDKs use. 

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:account_ids` ([String.t]): Repeatable. Restrict to specific connected accounts.
    - `:providers` ([String.t]): Repeatable. Restrict to provider ids (`google-calendar`, etc.).
    - `:"X-Workspace-ID"` (String.t): Workspace scope for unscoped tokens. Workspace-scoped PATs and OAuth tokens carry this implicitly; for session/JWT auth without a scoped PAT, pass it explicitly. 
    - `:timeMin` (DateTime.t): Inclusive lower-bound time. RFC3339 or RFC3339Nano.
    - `:timeMax` (DateTime.t): Inclusive upper-bound time.
    - `:limit` (integer()): Max events to return per page (default 50).

  ### Returns

  - `{:ok, Spatio.Model.ListCalendarEvents200Response.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec list_calendar_events(Tesla.Env.client, keyword()) :: {:ok, Spatio.Model.ListCalendarEvents200Response.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def list_calendar_events(connection, opts \\ []) do
    optional_params = %{
      :account_ids => :query,
      :providers => :query,
      :"X-Workspace-ID" => :headers,
      :timeMin => :query,
      :timeMax => :query,
      :limit => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/v1/calendar/events")
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Spatio.Model.ListCalendarEvents200Response},
      {401, Spatio.Model.ApiError},
      {500, Spatio.Model.ApiError}
    ])
  end

  @doc """
  List supported calendar providers.
  Static list of provider ids the Calendar platform can connect to. Returned regardless of which providers the caller has actually authorized. 

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, Spatio.Model.CalendarProvidersInfo.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec list_calendar_providers(Tesla.Env.client, keyword()) :: {:ok, Spatio.Model.CalendarProvidersInfo.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def list_calendar_providers(connection, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/calendar/providers")
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Spatio.Model.CalendarProvidersInfo},
      {401, Spatio.Model.ApiError}
    ])
  end

  @doc """
  Trigger a sync across connected calendar accounts.
  Enqueues sync jobs (one per connected calendar account) and returns immediately with the job ids. Pass `?wait=true` to block until all jobs complete (10-second polling budget); the response is then `200` with `waited: true` and a `timed_out` flag if any job didn't finish in time. 

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:wait` (boolean()): Block until all sync jobs finish (10s timeout).

  ### Returns

  - `{:ok, Spatio.Model.CalendarSyncResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec sync_calendar(Tesla.Env.client, keyword()) :: {:ok, Spatio.Model.CalendarSyncResponse.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def sync_calendar(connection, opts \\ []) do
    optional_params = %{
      :wait => :query
    }

    request =
      %{}
      |> method(:post)
      |> url("/v1/calendar/sync")
      |> add_optional_params(optional_params, opts)
      |> ensure_body()
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Spatio.Model.CalendarSyncResponse},
      {202, Spatio.Model.CalendarSyncResponse},
      {401, Spatio.Model.ApiError},
      {503, Spatio.Model.ApiError}
    ])
  end

  @doc """
  Update an event (sparse).
  Partial update. `account_id` may be supplied in the body (preferred) or as `?account_id=` query param — the renderer's update path puts it in the URL while create puts it in the body. `updates` is a free-form map; the platform's capability gate rejects fields the provider doesn't support. 

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `id` (String.t): Event id.
  - `update_event_request` (UpdateEventRequest): 
  - `opts` (keyword): Optional parameters
    - `:"X-Workspace-ID"` (String.t): Workspace scope for unscoped tokens. Workspace-scoped PATs and OAuth tokens carry this implicitly; for session/JWT auth without a scoped PAT, pass it explicitly. 
    - `:account_id` (String.t): Optional account-id filter (snake_case).

  ### Returns

  - `{:ok, Spatio.Model.CreateCalendarEvent201Response.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec update_calendar_event(Tesla.Env.client, String.t, Spatio.Model.UpdateEventRequest.t, keyword()) :: {:ok, Spatio.Model.CreateCalendarEvent201Response.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def update_calendar_event(connection, id, update_event_request, opts \\ []) do
    optional_params = %{
      :"X-Workspace-ID" => :headers,
      :account_id => :query
    }

    request =
      %{}
      |> method(:patch)
      |> url("/v1/calendar/events/#{id}")
      |> add_param(:body, :body, update_event_request)
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, Spatio.Model.CreateCalendarEvent201Response},
      {400, Spatio.Model.ApiError},
      {401, Spatio.Model.ApiError},
      {404, Spatio.Model.ApiError},
      {500, Spatio.Model.ApiError}
    ])
  end

  @doc """
  Workspace-scoped create-event (RBAC-protected).

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `org` (String.t): 
  - `workspace` (String.t): 
  - `request_body` (%{optional(String.t) => any()}): 
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, %{}}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec workspace_create_calendar_event(Tesla.Env.client, String.t, String.t, %{optional(String.t) => any()}, keyword()) :: {:ok, %{optional(String.t) => any()}} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def workspace_create_calendar_event(connection, org, workspace, request_body, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/calendar/events")
      |> add_param(:body, :body, request_body)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {201, %{}},
      {401, Spatio.Model.ApiError},
      {403, Spatio.Model.ApiError}
    ])
  end

  @doc """

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `org` (String.t): 
  - `workspace` (String.t): 
  - `id` (String.t): 
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, nil}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec workspace_delete_calendar_event(Tesla.Env.client, String.t, String.t, String.t, keyword()) :: {:ok, nil} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def workspace_delete_calendar_event(connection, org, workspace, id, _opts \\ []) do
    request =
      %{}
      |> method(:delete)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/calendar/events/#{id}")
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {204, false},
      {401, Spatio.Model.ApiError},
      {403, Spatio.Model.ApiError}
    ])
  end

  @doc """

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `org` (String.t): 
  - `workspace` (String.t): 
  - `id` (String.t): 
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, %{}}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec workspace_get_calendar_event(Tesla.Env.client, String.t, String.t, String.t, keyword()) :: {:ok, %{optional(String.t) => any()}} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def workspace_get_calendar_event(connection, org, workspace, id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/calendar/events/#{id}")
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, %{}},
      {401, Spatio.Model.ApiError},
      {403, Spatio.Model.ApiError},
      {404, Spatio.Model.ApiError}
    ])
  end

  @doc """
  Workspace-scoped list-events (RBAC-protected).

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `org` (String.t): 
  - `workspace` (String.t): 
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, %{}}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec workspace_list_calendar_events(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, %{optional(String.t) => any()}} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def workspace_list_calendar_events(connection, org, workspace, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/calendar/events")
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, %{}},
      {401, Spatio.Model.ApiError},
      {403, Spatio.Model.ApiError}
    ])
  end

  @doc """
  Workspace-scoped calendar providers.

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `org` (String.t): 
  - `workspace` (String.t): 
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, %{}}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec workspace_list_calendar_providers(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, %{optional(String.t) => any()}} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def workspace_list_calendar_providers(connection, org, workspace, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/calendar/providers")
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, %{}},
      {401, Spatio.Model.ApiError},
      {403, Spatio.Model.ApiError}
    ])
  end

  @doc """

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `org` (String.t): 
  - `workspace` (String.t): 
  - `id` (String.t): 
  - `request_body` (%{optional(String.t) => any()}): 
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, %{}}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec workspace_update_calendar_event(Tesla.Env.client, String.t, String.t, String.t, %{optional(String.t) => any()}, keyword()) :: {:ok, %{optional(String.t) => any()}} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def workspace_update_calendar_event(connection, org, workspace, id, request_body, _opts \\ []) do
    request =
      %{}
      |> method(:patch)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/calendar/events/#{id}")
      |> add_param(:body, :body, request_body)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, %{}},
      {401, Spatio.Model.ApiError},
      {403, Spatio.Model.ApiError}
    ])
  end
end