# WARNING: DO NOT EDIT, AUTO-GENERATED CODE!
# See https://github.com/aws-beam/aws-codegen for more details.

defmodule AWS.CloudFrontKeyValueStore do
  @moduledoc """
  Amazon CloudFront KeyValueStore Service to View and Update Data in a KVS
  Resource
  """

  alias AWS.Client
  alias AWS.Request

  @typedoc """

  ## Example:

      access_denied_exception() :: %{
        "Message" => [String.t() | atom()]
      }

  """
  @type access_denied_exception() :: %{(String.t() | atom()) => any()}

  @typedoc """

  ## Example:

      conflict_exception() :: %{
        "Message" => [String.t() | atom()]
      }

  """
  @type conflict_exception() :: %{(String.t() | atom()) => any()}

  @typedoc """

  ## Example:

      delete_key_request() :: %{
        required("IfMatch") => String.t() | atom()
      }

  """
  @type delete_key_request() :: %{(String.t() | atom()) => any()}

  @typedoc """

  ## Example:

      delete_key_request_list_item() :: %{
        "Key" => String.t() | atom()
      }

  """
  @type delete_key_request_list_item() :: %{(String.t() | atom()) => any()}

  @typedoc """

  ## Example:

      delete_key_response() :: %{
        "ETag" => String.t() | atom(),
        "ItemCount" => [integer()],
        "TotalSizeInBytes" => [float()]
      }

  """
  @type delete_key_response() :: %{(String.t() | atom()) => any()}

  @typedoc """

  ## Example:

      describe_key_value_store_request() :: %{}

  """
  @type describe_key_value_store_request() :: %{}

  @typedoc """

  ## Example:

      describe_key_value_store_response() :: %{
        "Created" => [non_neg_integer()],
        "ETag" => String.t() | atom(),
        "FailureReason" => [String.t() | atom()],
        "ItemCount" => [integer()],
        "KvsARN" => String.t() | atom(),
        "LastModified" => [non_neg_integer()],
        "Status" => [String.t() | atom()],
        "TotalSizeInBytes" => [float()]
      }

  """
  @type describe_key_value_store_response() :: %{(String.t() | atom()) => any()}

  @typedoc """

  ## Example:

      get_key_request() :: %{}

  """
  @type get_key_request() :: %{}

  @typedoc """

  ## Example:

      get_key_response() :: %{
        "ItemCount" => [integer()],
        "Key" => String.t() | atom(),
        "TotalSizeInBytes" => [float()],
        "Value" => String.t() | atom()
      }

  """
  @type get_key_response() :: %{(String.t() | atom()) => any()}

  @typedoc """

  ## Example:

      internal_server_exception() :: %{
        "Message" => [String.t() | atom()]
      }

  """
  @type internal_server_exception() :: %{(String.t() | atom()) => any()}

  @typedoc """

  ## Example:

      list_keys_request() :: %{
        optional("MaxResults") => [integer()],
        optional("NextToken") => [String.t() | atom()]
      }

  """
  @type list_keys_request() :: %{(String.t() | atom()) => any()}

  @typedoc """

  ## Example:

      list_keys_response() :: %{
        "Items" => list(list_keys_response_list_item()),
        "NextToken" => [String.t() | atom()]
      }

  """
  @type list_keys_response() :: %{(String.t() | atom()) => any()}

  @typedoc """

  ## Example:

      list_keys_response_list_item() :: %{
        "Key" => String.t() | atom(),
        "Value" => String.t() | atom()
      }

  """
  @type list_keys_response_list_item() :: %{(String.t() | atom()) => any()}

  @typedoc """

  ## Example:

      put_key_request() :: %{
        required("IfMatch") => String.t() | atom(),
        required("Value") => String.t() | atom()
      }

  """
  @type put_key_request() :: %{(String.t() | atom()) => any()}

  @typedoc """

  ## Example:

      put_key_request_list_item() :: %{
        "Key" => String.t() | atom(),
        "Value" => String.t() | atom()
      }

  """
  @type put_key_request_list_item() :: %{(String.t() | atom()) => any()}

  @typedoc """

  ## Example:

      put_key_response() :: %{
        "ETag" => String.t() | atom(),
        "ItemCount" => [integer()],
        "TotalSizeInBytes" => [float()]
      }

  """
  @type put_key_response() :: %{(String.t() | atom()) => any()}

  @typedoc """

  ## Example:

      resource_not_found_exception() :: %{
        "Message" => [String.t() | atom()]
      }

  """
  @type resource_not_found_exception() :: %{(String.t() | atom()) => any()}

  @typedoc """

  ## Example:

      service_quota_exceeded_exception() :: %{
        "Message" => [String.t() | atom()]
      }

  """
  @type service_quota_exceeded_exception() :: %{(String.t() | atom()) => any()}

  @typedoc """

  ## Example:

      update_keys_request() :: %{
        optional("Deletes") => list(delete_key_request_list_item()),
        optional("Puts") => list(put_key_request_list_item()),
        required("IfMatch") => String.t() | atom()
      }

  """
  @type update_keys_request() :: %{(String.t() | atom()) => any()}

  @typedoc """

  ## Example:

      update_keys_response() :: %{
        "ETag" => String.t() | atom(),
        "ItemCount" => [integer()],
        "TotalSizeInBytes" => [float()]
      }

  """
  @type update_keys_response() :: %{(String.t() | atom()) => any()}

  @typedoc """

  ## Example:

      validation_exception() :: %{
        "Message" => [String.t() | atom()]
      }

  """
  @type validation_exception() :: %{(String.t() | atom()) => any()}

  @type delete_key_errors() ::
          validation_exception()
          | service_quota_exceeded_exception()
          | resource_not_found_exception()
          | internal_server_exception()
          | conflict_exception()
          | access_denied_exception()

  @type describe_key_value_store_errors() ::
          resource_not_found_exception()
          | internal_server_exception()
          | conflict_exception()
          | access_denied_exception()

  @type get_key_errors() ::
          resource_not_found_exception()
          | internal_server_exception()
          | conflict_exception()
          | access_denied_exception()

  @type list_keys_errors() ::
          validation_exception()
          | resource_not_found_exception()
          | internal_server_exception()
          | conflict_exception()
          | access_denied_exception()

  @type put_key_errors() ::
          validation_exception()
          | service_quota_exceeded_exception()
          | resource_not_found_exception()
          | internal_server_exception()
          | conflict_exception()
          | access_denied_exception()

  @type update_keys_errors() ::
          validation_exception()
          | service_quota_exceeded_exception()
          | resource_not_found_exception()
          | internal_server_exception()
          | conflict_exception()
          | access_denied_exception()

  def metadata do
    %{
      api_version: "2022-07-26",
      content_type: "application/x-amz-json-1.1",
      credential_scope: nil,
      endpoint_prefix: "cloudfront-keyvaluestore",
      global?: false,
      hostname: nil,
      protocol: "rest-json",
      service_id: "CloudFront KeyValueStore",
      signature_version: "v4",
      signing_name: "cloudfront-keyvaluestore",
      target_prefix: nil
    }
  end

  @doc """
  Deletes the key value pair specified by the key.
  """
  @spec delete_key(map(), String.t() | atom(), String.t() | atom(), delete_key_request(), list()) ::
          {:ok, delete_key_response(), any()}
          | {:error, {:unexpected_response, any()}}
          | {:error, term()}
          | {:error, delete_key_errors()}
  def delete_key(%Client{} = client, key, kvs_arn, input, options \\ []) do
    url_path =
      "/key-value-stores/#{AWS.Util.encode_uri(kvs_arn)}/keys/#{AWS.Util.encode_uri(key)}"

    {headers, input} =
      [
        {"IfMatch", "If-Match"}
      ]
      |> Request.build_params(input)

    custom_headers = []
    query_params = []

    options =
      Keyword.put(
        options,
        :response_header_parameters,
        [{"ETag", "ETag"}]
      )

    meta = metadata()

    Request.request_rest(
      client,
      meta,
      :delete,
      url_path,
      query_params,
      custom_headers ++ headers,
      input,
      options,
      200
    )
  end

  @doc """
  Returns metadata information about Key Value Store.
  """
  @spec describe_key_value_store(map(), String.t() | atom(), list()) ::
          {:ok, describe_key_value_store_response(), any()}
          | {:error, {:unexpected_response, any()}}
          | {:error, term()}
          | {:error, describe_key_value_store_errors()}
  def describe_key_value_store(%Client{} = client, kvs_arn, options \\ []) do
    url_path = "/key-value-stores/#{AWS.Util.encode_uri(kvs_arn)}"
    headers = []
    query_params = []

    options =
      Keyword.put(
        options,
        :response_header_parameters,
        [{"ETag", "ETag"}]
      )

    meta = metadata()

    Request.request_rest(client, meta, :get, url_path, query_params, headers, nil, options, 200)
  end

  @doc """
  Returns a key value pair.
  """
  @spec get_key(map(), String.t() | atom(), String.t() | atom(), list()) ::
          {:ok, get_key_response(), any()}
          | {:error, {:unexpected_response, any()}}
          | {:error, term()}
          | {:error, get_key_errors()}
  def get_key(%Client{} = client, key, kvs_arn, options \\ []) do
    url_path =
      "/key-value-stores/#{AWS.Util.encode_uri(kvs_arn)}/keys/#{AWS.Util.encode_uri(key)}"

    headers = []
    query_params = []

    meta = metadata()

    Request.request_rest(client, meta, :get, url_path, query_params, headers, nil, options, 200)
  end

  @doc """
  Returns a list of key value pairs.
  """
  @spec list_keys(
          map(),
          String.t() | atom(),
          String.t() | atom() | nil,
          String.t() | atom() | nil,
          list()
        ) ::
          {:ok, list_keys_response(), any()}
          | {:error, {:unexpected_response, any()}}
          | {:error, term()}
          | {:error, list_keys_errors()}
  def list_keys(%Client{} = client, kvs_arn, max_results \\ nil, next_token \\ nil, options \\ []) do
    url_path = "/key-value-stores/#{AWS.Util.encode_uri(kvs_arn)}/keys"
    headers = []
    query_params = []

    query_params =
      if !is_nil(next_token) do
        [{"NextToken", next_token} | query_params]
      else
        query_params
      end

    query_params =
      if !is_nil(max_results) do
        [{"MaxResults", max_results} | query_params]
      else
        query_params
      end

    meta = metadata()

    Request.request_rest(client, meta, :get, url_path, query_params, headers, nil, options, 200)
  end

  @doc """
  Creates a new key value pair or replaces the value of an existing key.
  """
  @spec put_key(map(), String.t() | atom(), String.t() | atom(), put_key_request(), list()) ::
          {:ok, put_key_response(), any()}
          | {:error, {:unexpected_response, any()}}
          | {:error, term()}
          | {:error, put_key_errors()}
  def put_key(%Client{} = client, key, kvs_arn, input, options \\ []) do
    url_path =
      "/key-value-stores/#{AWS.Util.encode_uri(kvs_arn)}/keys/#{AWS.Util.encode_uri(key)}"

    {headers, input} =
      [
        {"IfMatch", "If-Match"}
      ]
      |> Request.build_params(input)

    custom_headers = []
    query_params = []

    options =
      Keyword.put(
        options,
        :response_header_parameters,
        [{"ETag", "ETag"}]
      )

    meta = metadata()

    Request.request_rest(
      client,
      meta,
      :put,
      url_path,
      query_params,
      custom_headers ++ headers,
      input,
      options,
      200
    )
  end

  @doc """
  Puts or Deletes multiple key value pairs in a single, all-or-nothing operation.
  """
  @spec update_keys(map(), String.t() | atom(), update_keys_request(), list()) ::
          {:ok, update_keys_response(), any()}
          | {:error, {:unexpected_response, any()}}
          | {:error, term()}
          | {:error, update_keys_errors()}
  def update_keys(%Client{} = client, kvs_arn, input, options \\ []) do
    url_path = "/key-value-stores/#{AWS.Util.encode_uri(kvs_arn)}/keys"

    {headers, input} =
      [
        {"IfMatch", "If-Match"}
      ]
      |> Request.build_params(input)

    custom_headers = []
    query_params = []

    options =
      Keyword.put(
        options,
        :response_header_parameters,
        [{"ETag", "ETag"}]
      )

    meta = metadata()

    Request.request_rest(
      client,
      meta,
      :post,
      url_path,
      query_params,
      custom_headers ++ headers,
      input,
      options,
      200
    )
  end
end
