{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.IoT.Types.ElasticsearchAction where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
      { $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 :: Lens' ElasticsearchAction Text
elasticsearchAction_roleArn = 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 :: Lens' ElasticsearchAction Text
elasticsearchAction_endpoint = 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 :: Lens' ElasticsearchAction Text
elasticsearchAction_index = 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 :: Lens' ElasticsearchAction Text
elasticsearchAction_type = 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 :: Lens' ElasticsearchAction Text
elasticsearchAction_id = 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 Data.FromJSON ElasticsearchAction where
  parseJSON :: Value -> Parser ElasticsearchAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ElasticsearchAction"
      ( \Object
x ->
          Text -> Text -> Text -> Text -> Text -> ElasticsearchAction
ElasticsearchAction'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"roleArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"endpoint")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"index")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"type")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"id")
      )

instance Prelude.Hashable ElasticsearchAction where
  hashWithSalt :: Int -> ElasticsearchAction -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
roleArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
endpoint
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
index
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
type'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
id

instance Prelude.NFData ElasticsearchAction where
  rnf :: ElasticsearchAction -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
roleArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
endpoint
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
index
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
type'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
id

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"roleArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
roleArn),
            forall a. a -> Maybe a
Prelude.Just (Key
"endpoint" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
endpoint),
            forall a. a -> Maybe a
Prelude.Just (Key
"index" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
index),
            forall a. a -> Maybe a
Prelude.Just (Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
type'),
            forall a. a -> Maybe a
Prelude.Just (Key
"id" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
id)
          ]
      )