lib/spatio/api/files.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.Files do
  @moduledoc """
  API calls for all endpoints tagged `Files`.
  """

  alias Spatio.Connection
  import Spatio.RequestBuilder

  @doc """
  Delete multiple files in one call.

  ### Parameters

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

  ### Returns

  - `{:ok, Spatio.Model.BulkFilesResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec bulk_delete_files(Tesla.Env.client, Spatio.Model.BulkDeleteFilesRequest.t, keyword()) :: {:ok, Spatio.Model.BulkFilesResponse.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def bulk_delete_files(connection, bulk_delete_files_request, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/files/delete")
      |> add_param(:body, :body, bulk_delete_files_request)
      |> Enum.into([])

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

  @doc """
  Move multiple files to a target folder.

  ### Parameters

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

  ### Returns

  - `{:ok, Spatio.Model.BulkFilesResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec bulk_move_files(Tesla.Env.client, Spatio.Model.BulkMoveFilesRequest.t, keyword()) :: {:ok, Spatio.Model.BulkFilesResponse.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def bulk_move_files(connection, bulk_move_files_request, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/files/move")
      |> add_param(:body, :body, bulk_move_files_request)
      |> Enum.into([])

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

  @doc """
  Finalize a chunked-upload session and create the file row.

  ### Parameters

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

  ### Returns

  - `{:ok, Spatio.Model.CommitChunkedUploadResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec commit_chunked_upload(Tesla.Env.client, Spatio.Model.CommitChunkedUploadRequest.t, keyword()) :: {:ok, Spatio.Model.CommitChunkedUploadResponse.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def commit_chunked_upload(connection, commit_chunked_upload_request, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/files/upload/chunked/commit")
      |> add_param(:body, :body, commit_chunked_upload_request)
      |> Enum.into([])

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

  @doc """
  Create a folder.

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `create_folder_request` (CreateFolderRequest): 
  - `opts` (keyword): Optional parameters
    - `:accountId` (String.t): Connected-account row id. Selects which provider account this request targets when more than one is connected. Mutually exclusive with `provider`. If omitted on a list endpoint the call fans out across every connected account. 
    - `:provider` (String.t): Provider id (e.g. `native-notes`, `notion`). Selects every connected account for the provider. Mutually exclusive with `accountId`. 
    - `:"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.Folder.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec create_file_folder(Tesla.Env.client, Spatio.Model.CreateFolderRequest.t, keyword()) :: {:ok, Spatio.Model.Folder.t} | {:ok, Spatio.Model.ApiError.t} | {:ok, Spatio.Model.CreateNote400Response.t} | {:error, Tesla.Env.t}
  def create_file_folder(connection, create_folder_request, opts \\ []) do
    optional_params = %{
      :accountId => :query,
      :provider => :query,
      :"X-Workspace-ID" => :headers
    }

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

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

  @doc """
  Delete a file.

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `id` (String.t): File id.
  - `opts` (keyword): Optional parameters
    - `:accountId` (String.t): Connected-account row id. Selects which provider account this request targets when more than one is connected. Mutually exclusive with `provider`. If omitted on a list endpoint the call fans out across every connected account. 
    - `:"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, nil}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec delete_file(Tesla.Env.client, String.t, keyword()) :: {:ok, nil} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def delete_file(connection, id, opts \\ []) do
    optional_params = %{
      :accountId => :query,
      :"X-Workspace-ID" => :headers
    }

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

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

  @doc """
  Extract text content from a PDF (or other supported file).

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `id` (String.t): File id.
  - `opts` (keyword): Optional parameters
    - `:accountId` (String.t): Connected-account row id. Selects which provider account this request targets when more than one is connected. Mutually exclusive with `provider`. If omitted on a list endpoint the call fans out across every connected account. 
    - `:"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. 
    - `:pageStart` (integer()): 
    - `:pageEnd` (integer()): 
    - `:maxChars` (integer()): Truncation limit; sets `truncated: true` when hit.

  ### Returns

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

    request =
      %{}
      |> method(:get)
      |> url("/v1/files/#{id}/extract-text")
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

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

  @doc """
  Fetch the block manifest for a chunked-uploaded file.
  Only meaningful for files uploaded via `upload/chunked/*`. Files uploaded via `upload` or `upload/base64` return `404`. 

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `id` (String.t): File id.
  - `opts` (keyword): Optional parameters
    - `:accountId` (String.t): Connected-account row id. Selects which provider account this request targets when more than one is connected. Mutually exclusive with `provider`. If omitted on a list endpoint the call fans out across every connected account. 
    - `:"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.ChunkedFileManifest.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec get_chunked_file_manifest(Tesla.Env.client, String.t, keyword()) :: {:ok, Spatio.Model.ChunkedFileManifest.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def get_chunked_file_manifest(connection, id, opts \\ []) do
    optional_params = %{
      :accountId => :query,
      :"X-Workspace-ID" => :headers
    }

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

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

  @doc """
  Fetch one file's metadata.

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `id` (String.t): File id.
  - `opts` (keyword): Optional parameters
    - `:accountId` (String.t): Connected-account row id. Selects which provider account this request targets when more than one is connected. Mutually exclusive with `provider`. If omitted on a list endpoint the call fans out across every connected account. 
    - `:"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.SpatioFile.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec get_file(Tesla.Env.client, String.t, keyword()) :: {:ok, Spatio.Model.ApiError.t} | {:ok, Spatio.Model.SpatioFile.t} | {:error, Tesla.Env.t}
  def get_file(connection, id, opts \\ []) do
    optional_params = %{
      :accountId => :query,
      :"X-Workspace-ID" => :headers
    }

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

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

  @doc """
  Mint a fresh signed download URL.
  Returns a JSON envelope with a pre-signed URL pointing at the backing storage. Clients follow the URL — the platform does not stream bytes through itself. 

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `id` (String.t): File id.
  - `opts` (keyword): Optional parameters
    - `:accountId` (String.t): Connected-account row id. Selects which provider account this request targets when more than one is connected. Mutually exclusive with `provider`. If omitted on a list endpoint the call fans out across every connected account. 
    - `:"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.DownloadFileResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec get_file_download_url(Tesla.Env.client, String.t, keyword()) :: {:ok, Spatio.Model.DownloadFileResponse.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def get_file_download_url(connection, id, opts \\ []) do
    optional_params = %{
      :accountId => :query,
      :"X-Workspace-ID" => :headers
    }

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

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

  @doc """
  Begin a content-addressed chunked upload session.
  Client computes per-block hashes ahead of time and submits the list. The server replies with which blocks need uploading vs. already-on-server (deduplicated). Subsequent calls upload the missing blocks via `uploadChunkedBlock`, then `commit`. 

  ### Parameters

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

  ### Returns

  - `{:ok, Spatio.Model.InitChunkedUploadResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec init_chunked_upload(Tesla.Env.client, Spatio.Model.InitChunkedUploadRequest.t, keyword()) :: {:ok, Spatio.Model.InitChunkedUploadResponse.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def init_chunked_upload(connection, init_chunked_upload_request, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/files/upload/chunked/init")
      |> add_param(:body, :body, init_chunked_upload_request)
      |> Enum.into([])

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

  @doc """
  List folders across connected file providers.

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:accountId` (String.t): Connected-account row id. Selects which provider account this request targets when more than one is connected. Mutually exclusive with `provider`. If omitted on a list endpoint the call fans out across every connected account. 
    - `:provider` (String.t): Provider id (e.g. `native-notes`, `notion`). Selects every connected account for the provider. Mutually exclusive with `accountId`. 
    - `:"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. 
    - `:parentId` (String.t): Filter to children of this folder. Omit for root.
    - `:workspaceId` (String.t): 
    - `:organizationId` (String.t): 
    - `:limit` (integer()): 
    - `:offset` (integer()): 

  ### Returns

  - `{:ok, Spatio.Model.FolderListEnvelope.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec list_file_folders(Tesla.Env.client, keyword()) :: {:ok, Spatio.Model.FolderListEnvelope.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def list_file_folders(connection, opts \\ []) do
    optional_params = %{
      :accountId => :query,
      :provider => :query,
      :"X-Workspace-ID" => :headers,
      :parentId => :query,
      :workspaceId => :query,
      :organizationId => :query,
      :limit => :query,
      :offset => :query
    }

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

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

  @doc """
  List files across connected file providers.
  Fan-out list. Returns files from every connected file provider unless filtered by `?accountId=` or `?provider=`. Folder contents are scoped via `?folderId=`; omit for account root. 

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:accountId` (String.t): Connected-account row id. Selects which provider account this request targets when more than one is connected. Mutually exclusive with `provider`. If omitted on a list endpoint the call fans out across every connected account. 
    - `:provider` (String.t): Provider id (e.g. `native-notes`, `notion`). Selects every connected account for the provider. Mutually exclusive with `accountId`. 
    - `:"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. 
    - `:folderId` (String.t): Filter to one folder. Omit for the account root.
    - `:workspaceId` (String.t): 
    - `:organizationId` (String.t): 
    - `:limit` (integer()): 
    - `:offset` (integer()): 
    - `:sortBy` (String.t): Provider-dependent. Common values: `created_at`, `name`, `size`.
    - `:sortOrder` (String.t): 

  ### Returns

  - `{:ok, Spatio.Model.FileListEnvelope.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec list_files(Tesla.Env.client, keyword()) :: {:ok, Spatio.Model.FileListEnvelope.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def list_files(connection, opts \\ []) do
    optional_params = %{
      :accountId => :query,
      :provider => :query,
      :"X-Workspace-ID" => :headers,
      :folderId => :query,
      :workspaceId => :query,
      :organizationId => :query,
      :limit => :query,
      :offset => :query,
      :sortBy => :query,
      :sortOrder => :query
    }

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

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

  @doc """
  Aggregate list of files + folders for renderer file-browser views.
  Calls `listFiles` and `listFileFolders` in parallel and merges the results. Saves a round-trip when the UI shows both side-by-side. 

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `opts` (keyword): Optional parameters
    - `:accountId` (String.t): Connected-account row id. Selects which provider account this request targets when more than one is connected. Mutually exclusive with `provider`. If omitted on a list endpoint the call fans out across every connected account. 
    - `:provider` (String.t): Provider id (e.g. `native-notes`, `notion`). Selects every connected account for the provider. Mutually exclusive with `accountId`. 
    - `:folderId` (String.t): Filter to one folder. Omit for the account root.
    - `:workspaceId` (String.t): 
    - `:organizationId` (String.t): 
    - `:limit` (integer()): 
    - `:offset` (integer()): 
    - `:sortBy` (String.t): 
    - `:sortOrder` (String.t): 

  ### Returns

  - `{:ok, Spatio.Model.FilesAndFoldersResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec list_files_and_folders(Tesla.Env.client, keyword()) :: {:ok, Spatio.Model.FilesAndFoldersResponse.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def list_files_and_folders(connection, opts \\ []) do
    optional_params = %{
      :accountId => :query,
      :provider => :query,
      :folderId => :query,
      :workspaceId => :query,
      :organizationId => :query,
      :limit => :query,
      :offset => :query,
      :sortBy => :query,
      :sortOrder => :query
    }

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

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

  @doc """
  Move a single file to a target folder.

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `id` (String.t): File id.
  - `move_file_request` (MoveFileRequest): 
  - `opts` (keyword): Optional parameters
    - `:accountId` (String.t): Connected-account row id. Selects which provider account this request targets when more than one is connected. Mutually exclusive with `provider`. If omitted on a list endpoint the call fans out across every connected account. 
    - `:"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.MoveFileResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec move_file(Tesla.Env.client, String.t, Spatio.Model.MoveFileRequest.t, keyword()) :: {:ok, Spatio.Model.MoveFileResponse.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def move_file(connection, id, move_file_request, opts \\ []) do
    optional_params = %{
      :accountId => :query,
      :"X-Workspace-ID" => :headers
    }

    request =
      %{}
      |> method(:post)
      |> url("/v1/files/#{id}/move")
      |> add_param(:body, :body, move_file_request)
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

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

  @doc """
  Substring-match search across the caller's files.
  In-memory search — the platform lists up to ~500 files and filters locally on `name` (case-insensitive substring). Not suitable for global search across very large file libraries. 

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `query` (String.t): 
  - `opts` (keyword): Optional parameters
    - `:accountId` (String.t): Connected-account row id. Selects which provider account this request targets when more than one is connected. Mutually exclusive with `provider`. If omitted on a list endpoint the call fans out across every connected account. 
    - `:provider` (String.t): Provider id (e.g. `native-notes`, `notion`). Selects every connected account for the provider. Mutually exclusive with `accountId`. 
    - `:folderId` (String.t): Filter to one folder. Omit for the account root.
    - `:workspaceId` (String.t): 
    - `:organizationId` (String.t): 
    - `:limit` (integer()): 
    - `:offset` (integer()): 

  ### Returns

  - `{:ok, Spatio.Model.SearchFilesResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec search_files(Tesla.Env.client, String.t, keyword()) :: {:ok, Spatio.Model.SearchFilesResponse.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def search_files(connection, query, opts \\ []) do
    optional_params = %{
      :accountId => :query,
      :provider => :query,
      :folderId => :query,
      :workspaceId => :query,
      :organizationId => :query,
      :limit => :query,
      :offset => :query
    }

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

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

  @doc """
  Update a file's metadata (name, folder, custom fields).

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `id` (String.t): File id.
  - `update_file_request` (UpdateFileRequest): 
  - `opts` (keyword): Optional parameters
    - `:accountId` (String.t): Connected-account row id. Selects which provider account this request targets when more than one is connected. Mutually exclusive with `provider`. If omitted on a list endpoint the call fans out across every connected account. 
    - `:"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.SpatioFile.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec update_file(Tesla.Env.client, String.t, Spatio.Model.UpdateFileRequest.t, keyword()) :: {:ok, Spatio.Model.ApiError.t} | {:ok, Spatio.Model.SpatioFile.t} | {:error, Tesla.Env.t}
  def update_file(connection, id, update_file_request, opts \\ []) do
    optional_params = %{
      :accountId => :query,
      :"X-Workspace-ID" => :headers
    }

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

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

  @doc """
  Upload one block for an open chunked-upload session.

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `session_id` (String.t): 
  - `block_hash` (String.t): 
  - `block` (String.t): 
  - `opts` (keyword): Optional parameters
    - `:blockIndex` (integer()): 

  ### Returns

  - `{:ok, Spatio.Model.UploadChunkedBlockResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec upload_chunked_block(Tesla.Env.client, String.t, String.t, String.t, keyword()) :: {:ok, Spatio.Model.UploadChunkedBlockResponse.t} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def upload_chunked_block(connection, session_id, block_hash, block, opts \\ []) do
    optional_params = %{
      :blockIndex => :form
    }

    request =
      %{}
      |> method(:post)
      |> url("/v1/files/upload/chunked/blocks")
      |> add_param(:form, :sessionId, session_id)
      |> add_param(:form, :blockHash, block_hash)
      |> add_param(:file, :block, block)
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

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

  @doc """
  Upload a file via multipart form.
  Multipart upload. Form field `file` carries the binary; auxiliary form fields scope the upload (`folderId`, `workspaceId`, `organizationId`, `accountId`). Max body size is currently 100 MB. 

  ### Parameters

  - `connection` (Spatio.Connection): Connection to server
  - `file` (String.t): File bytes (multipart form field name `file`).
  - `opts` (keyword): Optional parameters
    - `:folderId` (String.t): 
    - `:workspaceId` (String.t): 
    - `:organizationId` (String.t): 
    - `:accountId` (String.t): 

  ### Returns

  - `{:ok, Spatio.Model.SpatioFile.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec upload_file(Tesla.Env.client, String.t, keyword()) :: {:ok, Spatio.Model.QuotaExceededError.t} | {:ok, Spatio.Model.ApiError.t} | {:ok, Spatio.Model.CreateNote400Response.t} | {:ok, Spatio.Model.SpatioFile.t} | {:error, Tesla.Env.t}
  def upload_file(connection, file, opts \\ []) do
    optional_params = %{
      :folderId => :form,
      :workspaceId => :form,
      :organizationId => :form,
      :accountId => :form
    }

    request =
      %{}
      |> method(:post)
      |> url("/v1/files/upload")
      |> add_param(:file, :file, file)
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

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

  @doc """
  Upload a file via JSON with base64-encoded content.
  Equivalent to `uploadFile` for clients that can't post multipart bodies (e.g. browser fetch with strict CSP). 

  ### Parameters

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

  ### Returns

  - `{:ok, Spatio.Model.SpatioFile.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec upload_file_base64(Tesla.Env.client, Spatio.Model.UploadFileBase64Request.t, keyword()) :: {:ok, Spatio.Model.QuotaExceededError.t} | {:ok, Spatio.Model.ApiError.t} | {:ok, Spatio.Model.CreateNote400Response.t} | {:ok, Spatio.Model.SpatioFile.t} | {:error, Tesla.Env.t}
  def upload_file_base64(connection, upload_file_base64_request, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/files/upload/base64")
      |> add_param(:body, :body, upload_file_base64_request)
      |> Enum.into([])

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

  @doc """
  Workspace-scoped chunked-upload commit (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_commit_chunked_upload(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_commit_chunked_upload(connection, org, workspace, request_body, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/files/upload/chunked/commit")
      |> add_param(:body, :body, request_body)
      |> Enum.into([])

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

  @doc """
  Workspace-scoped create-folder (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_file_folder(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_file_folder(connection, org, workspace, request_body, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/files/folders")
      |> 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 """
  Workspace-scoped delete-file.

  ### 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_file(Tesla.Env.client, String.t, String.t, String.t, keyword()) :: {:ok, nil} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def workspace_delete_file(connection, org, workspace, id, _opts \\ []) do
    request =
      %{}
      |> method(:delete)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/files/#{id}")
      |> Enum.into([])

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

  @doc """
  Workspace-scoped get-file.

  ### 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_file(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_file(connection, org, workspace, id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/files/#{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 signed-download URL.

  ### 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_file_download(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_file_download(connection, org, workspace, id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/files/#{id}/download")
      |> 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 chunked-file manifest.

  ### 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_file_manifest(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_file_manifest(connection, org, workspace, id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/files/#{id}/manifest")
      |> 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 chunked-upload init (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_init_chunked_upload(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_init_chunked_upload(connection, org, workspace, request_body, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/files/upload/chunked/init")
      |> add_param(:body, :body, request_body)
      |> Enum.into([])

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

  @doc """
  Workspace-scoped list-folders (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_file_folders(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_file_folders(connection, org, workspace, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/files/folders")
      |> Enum.into([])

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

  @doc """
  Workspace-scoped list-files (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_files(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_files(connection, org, workspace, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/files")
      |> Enum.into([])

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

  @doc """
  Workspace-scoped move-file.

  ### 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_move_file(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_move_file(connection, org, workspace, id, request_body, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/files/#{id}/move")
      |> add_param(:body, :body, request_body)
      |> Enum.into([])

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

  @doc """
  Workspace-scoped update-file.

  ### 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_file(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_file(connection, org, workspace, id, request_body, _opts \\ []) do
    request =
      %{}
      |> method(:patch)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/files/#{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

  @doc """
  Workspace-scoped chunked-upload block (RBAC-protected).

  ### Parameters

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

  ### Returns

  - `{:ok, %{}}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec workspace_upload_chunked_block(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_upload_chunked_block(connection, org, workspace, body, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/files/upload/chunked/blocks")
      |> add_param(:body, :body, body)
      |> Enum.into([])

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

  @doc """
  Workspace-scoped multipart upload (RBAC-protected).

  ### Parameters

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

  ### Returns

  - `{:ok, %{}}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec workspace_upload_file(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, %{optional(String.t) => any()}} | {:ok, Spatio.Model.ApiError.t} | {:error, Tesla.Env.t}
  def workspace_upload_file(connection, org, workspace, opts \\ []) do
    optional_params = %{
      :file => :form
    }

    request =
      %{}
      |> method(:post)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/files/upload")
      |> add_optional_params(optional_params, opts)
      |> ensure_body()
      |> Enum.into([])

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

  @doc """
  Workspace-scoped base64 upload (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_upload_file_base64(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_upload_file_base64(connection, org, workspace, request_body, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/v1/organizations/#{org}/workspaces/#{workspace}/files/upload/base64")
      |> add_param(:body, :body, request_body)
      |> Enum.into([])

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