{-# 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.OpenSearchAction
-- 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.OpenSearchAction 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.
--
-- /See:/ 'newOpenSearchAction' smart constructor.
data OpenSearchAction = OpenSearchAction'
  { -- | The IAM role ARN that has access to OpenSearch.
    OpenSearchAction -> Text
roleArn :: Prelude.Text,
    -- | The endpoint of your OpenSearch domain.
    OpenSearchAction -> Text
endpoint :: Prelude.Text,
    -- | The OpenSearch index where you want to store your data.
    OpenSearchAction -> Text
index :: Prelude.Text,
    -- | The type of document you are storing.
    OpenSearchAction -> Text
type' :: Prelude.Text,
    -- | The unique identifier for the document you are storing.
    OpenSearchAction -> Text
id :: Prelude.Text
  }
  deriving (OpenSearchAction -> OpenSearchAction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OpenSearchAction -> OpenSearchAction -> Bool
$c/= :: OpenSearchAction -> OpenSearchAction -> Bool
== :: OpenSearchAction -> OpenSearchAction -> Bool
$c== :: OpenSearchAction -> OpenSearchAction -> Bool
Prelude.Eq, ReadPrec [OpenSearchAction]
ReadPrec OpenSearchAction
Int -> ReadS OpenSearchAction
ReadS [OpenSearchAction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OpenSearchAction]
$creadListPrec :: ReadPrec [OpenSearchAction]
readPrec :: ReadPrec OpenSearchAction
$creadPrec :: ReadPrec OpenSearchAction
readList :: ReadS [OpenSearchAction]
$creadList :: ReadS [OpenSearchAction]
readsPrec :: Int -> ReadS OpenSearchAction
$creadsPrec :: Int -> ReadS OpenSearchAction
Prelude.Read, Int -> OpenSearchAction -> ShowS
[OpenSearchAction] -> ShowS
OpenSearchAction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OpenSearchAction] -> ShowS
$cshowList :: [OpenSearchAction] -> ShowS
show :: OpenSearchAction -> String
$cshow :: OpenSearchAction -> String
showsPrec :: Int -> OpenSearchAction -> ShowS
$cshowsPrec :: Int -> OpenSearchAction -> ShowS
Prelude.Show, forall x. Rep OpenSearchAction x -> OpenSearchAction
forall x. OpenSearchAction -> Rep OpenSearchAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OpenSearchAction x -> OpenSearchAction
$cfrom :: forall x. OpenSearchAction -> Rep OpenSearchAction x
Prelude.Generic)

-- |
-- Create a value of 'OpenSearchAction' 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', 'openSearchAction_roleArn' - The IAM role ARN that has access to OpenSearch.
--
-- 'endpoint', 'openSearchAction_endpoint' - The endpoint of your OpenSearch domain.
--
-- 'index', 'openSearchAction_index' - The OpenSearch index where you want to store your data.
--
-- 'type'', 'openSearchAction_type' - The type of document you are storing.
--
-- 'id', 'openSearchAction_id' - The unique identifier for the document you are storing.
newOpenSearchAction ::
  -- | 'roleArn'
  Prelude.Text ->
  -- | 'endpoint'
  Prelude.Text ->
  -- | 'index'
  Prelude.Text ->
  -- | 'type''
  Prelude.Text ->
  -- | 'id'
  Prelude.Text ->
  OpenSearchAction
newOpenSearchAction :: Text -> Text -> Text -> Text -> Text -> OpenSearchAction
newOpenSearchAction
  Text
pRoleArn_
  Text
pEndpoint_
  Text
pIndex_
  Text
pType_
  Text
pId_ =
    OpenSearchAction'
      { $sel:roleArn:OpenSearchAction' :: Text
roleArn = Text
pRoleArn_,
        $sel:endpoint:OpenSearchAction' :: Text
endpoint = Text
pEndpoint_,
        $sel:index:OpenSearchAction' :: Text
index = Text
pIndex_,
        $sel:type':OpenSearchAction' :: Text
type' = Text
pType_,
        $sel:id:OpenSearchAction' :: Text
id = Text
pId_
      }

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

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

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

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

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

instance Data.FromJSON OpenSearchAction where
  parseJSON :: Value -> Parser OpenSearchAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"OpenSearchAction"
      ( \Object
x ->
          Text -> Text -> Text -> Text -> Text -> OpenSearchAction
OpenSearchAction'
            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 OpenSearchAction where
  hashWithSalt :: Int -> OpenSearchAction -> Int
hashWithSalt Int
_salt OpenSearchAction' {Text
id :: Text
type' :: Text
index :: Text
endpoint :: Text
roleArn :: Text
$sel:id:OpenSearchAction' :: OpenSearchAction -> Text
$sel:type':OpenSearchAction' :: OpenSearchAction -> Text
$sel:index:OpenSearchAction' :: OpenSearchAction -> Text
$sel:endpoint:OpenSearchAction' :: OpenSearchAction -> Text
$sel:roleArn:OpenSearchAction' :: OpenSearchAction -> 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 OpenSearchAction where
  rnf :: OpenSearchAction -> ()
rnf OpenSearchAction' {Text
id :: Text
type' :: Text
index :: Text
endpoint :: Text
roleArn :: Text
$sel:id:OpenSearchAction' :: OpenSearchAction -> Text
$sel:type':OpenSearchAction' :: OpenSearchAction -> Text
$sel:index:OpenSearchAction' :: OpenSearchAction -> Text
$sel:endpoint:OpenSearchAction' :: OpenSearchAction -> Text
$sel:roleArn:OpenSearchAction' :: OpenSearchAction -> 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 OpenSearchAction where
  toJSON :: OpenSearchAction -> Value
toJSON OpenSearchAction' {Text
id :: Text
type' :: Text
index :: Text
endpoint :: Text
roleArn :: Text
$sel:id:OpenSearchAction' :: OpenSearchAction -> Text
$sel:type':OpenSearchAction' :: OpenSearchAction -> Text
$sel:index:OpenSearchAction' :: OpenSearchAction -> Text
$sel:endpoint:OpenSearchAction' :: OpenSearchAction -> Text
$sel:roleArn:OpenSearchAction' :: OpenSearchAction -> 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)
          ]
      )