{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.IoT.Types.ElasticsearchAction
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.IoT.Types.ElasticsearchAction where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes an action that writes data to an Amazon OpenSearch Service
-- domain.
--
-- The @Elasticsearch@ action can only be used by existing rule actions. To
-- create a new rule action or to update an existing rule action, use the
-- @OpenSearch@ rule action instead. For more information, see
-- <https://docs.aws.amazon.com/iot/latest/apireference/API_OpenSearchAction.html OpenSearchAction>.
--
-- /See:/ 'newElasticsearchAction' smart constructor.
data ElasticsearchAction = ElasticsearchAction'
  { -- | The IAM role ARN that has access to OpenSearch.
    ElasticsearchAction -> Text
roleArn :: Prelude.Text,
    -- | The endpoint of your OpenSearch domain.
    ElasticsearchAction -> Text
endpoint :: Prelude.Text,
    -- | The index where you want to store your data.
    ElasticsearchAction -> Text
index :: Prelude.Text,
    -- | The type of document you are storing.
    ElasticsearchAction -> Text
type' :: Prelude.Text,
    -- | The unique identifier for the document you are storing.
    ElasticsearchAction -> Text
id :: Prelude.Text
  }
  deriving (ElasticsearchAction -> ElasticsearchAction -> Bool
(ElasticsearchAction -> ElasticsearchAction -> Bool)
-> (ElasticsearchAction -> ElasticsearchAction -> Bool)
-> Eq ElasticsearchAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ElasticsearchAction -> ElasticsearchAction -> Bool
$c/= :: ElasticsearchAction -> ElasticsearchAction -> Bool
== :: ElasticsearchAction -> ElasticsearchAction -> Bool
$c== :: ElasticsearchAction -> ElasticsearchAction -> Bool
Prelude.Eq, ReadPrec [ElasticsearchAction]
ReadPrec ElasticsearchAction
Int -> ReadS ElasticsearchAction
ReadS [ElasticsearchAction]
(Int -> ReadS ElasticsearchAction)
-> ReadS [ElasticsearchAction]
-> ReadPrec ElasticsearchAction
-> ReadPrec [ElasticsearchAction]
-> Read ElasticsearchAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ElasticsearchAction]
$creadListPrec :: ReadPrec [ElasticsearchAction]
readPrec :: ReadPrec ElasticsearchAction
$creadPrec :: ReadPrec ElasticsearchAction
readList :: ReadS [ElasticsearchAction]
$creadList :: ReadS [ElasticsearchAction]
readsPrec :: Int -> ReadS ElasticsearchAction
$creadsPrec :: Int -> ReadS ElasticsearchAction
Prelude.Read, Int -> ElasticsearchAction -> ShowS
[ElasticsearchAction] -> ShowS
ElasticsearchAction -> String
(Int -> ElasticsearchAction -> ShowS)
-> (ElasticsearchAction -> String)
-> ([ElasticsearchAction] -> ShowS)
-> Show ElasticsearchAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ElasticsearchAction] -> ShowS
$cshowList :: [ElasticsearchAction] -> ShowS
show :: ElasticsearchAction -> String
$cshow :: ElasticsearchAction -> String
showsPrec :: Int -> ElasticsearchAction -> ShowS
$cshowsPrec :: Int -> ElasticsearchAction -> ShowS
Prelude.Show, (forall x. ElasticsearchAction -> Rep ElasticsearchAction x)
-> (forall x. Rep ElasticsearchAction x -> ElasticsearchAction)
-> Generic ElasticsearchAction
forall x. Rep ElasticsearchAction x -> ElasticsearchAction
forall x. ElasticsearchAction -> Rep ElasticsearchAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ElasticsearchAction x -> ElasticsearchAction
$cfrom :: forall x. ElasticsearchAction -> Rep ElasticsearchAction x
Prelude.Generic)

-- |
-- Create a value of 'ElasticsearchAction' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'roleArn', 'elasticsearchAction_roleArn' - The IAM role ARN that has access to OpenSearch.
--
-- 'endpoint', 'elasticsearchAction_endpoint' - The endpoint of your OpenSearch domain.
--
-- 'index', 'elasticsearchAction_index' - The index where you want to store your data.
--
-- 'type'', 'elasticsearchAction_type' - The type of document you are storing.
--
-- 'id', 'elasticsearchAction_id' - The unique identifier for the document you are storing.
newElasticsearchAction ::
  -- | 'roleArn'
  Prelude.Text ->
  -- | 'endpoint'
  Prelude.Text ->
  -- | 'index'
  Prelude.Text ->
  -- | 'type''
  Prelude.Text ->
  -- | 'id'
  Prelude.Text ->
  ElasticsearchAction
newElasticsearchAction :: Text -> Text -> Text -> Text -> Text -> ElasticsearchAction
newElasticsearchAction
  Text
pRoleArn_
  Text
pEndpoint_
  Text
pIndex_
  Text
pType_
  Text
pId_ =
    ElasticsearchAction' :: Text -> Text -> Text -> Text -> Text -> ElasticsearchAction
ElasticsearchAction'
      { $sel:roleArn:ElasticsearchAction' :: Text
roleArn = Text
pRoleArn_,
        $sel:endpoint:ElasticsearchAction' :: Text
endpoint = Text
pEndpoint_,
        $sel:index:ElasticsearchAction' :: Text
index = Text
pIndex_,
        $sel:type':ElasticsearchAction' :: Text
type' = Text
pType_,
        $sel:id:ElasticsearchAction' :: Text
id = Text
pId_
      }

-- | The IAM role ARN that has access to OpenSearch.
elasticsearchAction_roleArn :: Lens.Lens' ElasticsearchAction Prelude.Text
elasticsearchAction_roleArn :: (Text -> f Text) -> ElasticsearchAction -> f ElasticsearchAction
elasticsearchAction_roleArn = (ElasticsearchAction -> Text)
-> (ElasticsearchAction -> Text -> ElasticsearchAction)
-> Lens ElasticsearchAction ElasticsearchAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ElasticsearchAction' {Text
roleArn :: Text
$sel:roleArn:ElasticsearchAction' :: ElasticsearchAction -> Text
roleArn} -> Text
roleArn) (\s :: ElasticsearchAction
s@ElasticsearchAction' {} Text
a -> ElasticsearchAction
s {$sel:roleArn:ElasticsearchAction' :: Text
roleArn = Text
a} :: ElasticsearchAction)

-- | The endpoint of your OpenSearch domain.
elasticsearchAction_endpoint :: Lens.Lens' ElasticsearchAction Prelude.Text
elasticsearchAction_endpoint :: (Text -> f Text) -> ElasticsearchAction -> f ElasticsearchAction
elasticsearchAction_endpoint = (ElasticsearchAction -> Text)
-> (ElasticsearchAction -> Text -> ElasticsearchAction)
-> Lens ElasticsearchAction ElasticsearchAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ElasticsearchAction' {Text
endpoint :: Text
$sel:endpoint:ElasticsearchAction' :: ElasticsearchAction -> Text
endpoint} -> Text
endpoint) (\s :: ElasticsearchAction
s@ElasticsearchAction' {} Text
a -> ElasticsearchAction
s {$sel:endpoint:ElasticsearchAction' :: Text
endpoint = Text
a} :: ElasticsearchAction)

-- | The index where you want to store your data.
elasticsearchAction_index :: Lens.Lens' ElasticsearchAction Prelude.Text
elasticsearchAction_index :: (Text -> f Text) -> ElasticsearchAction -> f ElasticsearchAction
elasticsearchAction_index = (ElasticsearchAction -> Text)
-> (ElasticsearchAction -> Text -> ElasticsearchAction)
-> Lens ElasticsearchAction ElasticsearchAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ElasticsearchAction' {Text
index :: Text
$sel:index:ElasticsearchAction' :: ElasticsearchAction -> Text
index} -> Text
index) (\s :: ElasticsearchAction
s@ElasticsearchAction' {} Text
a -> ElasticsearchAction
s {$sel:index:ElasticsearchAction' :: Text
index = Text
a} :: ElasticsearchAction)

-- | The type of document you are storing.
elasticsearchAction_type :: Lens.Lens' ElasticsearchAction Prelude.Text
elasticsearchAction_type :: (Text -> f Text) -> ElasticsearchAction -> f ElasticsearchAction
elasticsearchAction_type = (ElasticsearchAction -> Text)
-> (ElasticsearchAction -> Text -> ElasticsearchAction)
-> Lens ElasticsearchAction ElasticsearchAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ElasticsearchAction' {Text
type' :: Text
$sel:type':ElasticsearchAction' :: ElasticsearchAction -> Text
type'} -> Text
type') (\s :: ElasticsearchAction
s@ElasticsearchAction' {} Text
a -> ElasticsearchAction
s {$sel:type':ElasticsearchAction' :: Text
type' = Text
a} :: ElasticsearchAction)

-- | The unique identifier for the document you are storing.
elasticsearchAction_id :: Lens.Lens' ElasticsearchAction Prelude.Text
elasticsearchAction_id :: (Text -> f Text) -> ElasticsearchAction -> f ElasticsearchAction
elasticsearchAction_id = (ElasticsearchAction -> Text)
-> (ElasticsearchAction -> Text -> ElasticsearchAction)
-> Lens ElasticsearchAction ElasticsearchAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ElasticsearchAction' {Text
id :: Text
$sel:id:ElasticsearchAction' :: ElasticsearchAction -> Text
id} -> Text
id) (\s :: ElasticsearchAction
s@ElasticsearchAction' {} Text
a -> ElasticsearchAction
s {$sel:id:ElasticsearchAction' :: Text
id = Text
a} :: ElasticsearchAction)

instance Core.FromJSON ElasticsearchAction where
  parseJSON :: Value -> Parser ElasticsearchAction
parseJSON =
    String
-> (Object -> Parser ElasticsearchAction)
-> Value
-> Parser ElasticsearchAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ElasticsearchAction"
      ( \Object
x ->
          Text -> Text -> Text -> Text -> Text -> ElasticsearchAction
ElasticsearchAction'
            (Text -> Text -> Text -> Text -> Text -> ElasticsearchAction)
-> Parser Text
-> Parser (Text -> Text -> Text -> Text -> ElasticsearchAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"roleArn")
            Parser (Text -> Text -> Text -> Text -> ElasticsearchAction)
-> Parser Text
-> Parser (Text -> Text -> Text -> ElasticsearchAction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"endpoint")
            Parser (Text -> Text -> Text -> ElasticsearchAction)
-> Parser Text -> Parser (Text -> Text -> ElasticsearchAction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"index")
            Parser (Text -> Text -> ElasticsearchAction)
-> Parser Text -> Parser (Text -> ElasticsearchAction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"type")
            Parser (Text -> ElasticsearchAction)
-> Parser Text -> Parser ElasticsearchAction
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"id")
      )

instance Prelude.Hashable ElasticsearchAction

instance Prelude.NFData ElasticsearchAction

instance Core.ToJSON ElasticsearchAction where
  toJSON :: ElasticsearchAction -> Value
toJSON ElasticsearchAction' {Text
id :: Text
type' :: Text
index :: Text
endpoint :: Text
roleArn :: Text
$sel:id:ElasticsearchAction' :: ElasticsearchAction -> Text
$sel:type':ElasticsearchAction' :: ElasticsearchAction -> Text
$sel:index:ElasticsearchAction' :: ElasticsearchAction -> Text
$sel:endpoint:ElasticsearchAction' :: ElasticsearchAction -> Text
$sel:roleArn:ElasticsearchAction' :: ElasticsearchAction -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"roleArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
roleArn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"endpoint" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
endpoint),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"index" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
index),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"type" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
type'),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
id)
          ]
      )