{-# 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-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.OpenSearchAction 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.
--
-- /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
(OpenSearchAction -> OpenSearchAction -> Bool)
-> (OpenSearchAction -> OpenSearchAction -> Bool)
-> Eq OpenSearchAction
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]
(Int -> ReadS OpenSearchAction)
-> ReadS [OpenSearchAction]
-> ReadPrec OpenSearchAction
-> ReadPrec [OpenSearchAction]
-> Read 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
(Int -> OpenSearchAction -> ShowS)
-> (OpenSearchAction -> String)
-> ([OpenSearchAction] -> ShowS)
-> Show OpenSearchAction
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. OpenSearchAction -> Rep OpenSearchAction x)
-> (forall x. Rep OpenSearchAction x -> OpenSearchAction)
-> Generic OpenSearchAction
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' :: Text -> Text -> Text -> Text -> Text -> OpenSearchAction
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 :: (Text -> f Text) -> OpenSearchAction -> f OpenSearchAction
openSearchAction_roleArn = (OpenSearchAction -> Text)
-> (OpenSearchAction -> Text -> OpenSearchAction)
-> Lens OpenSearchAction OpenSearchAction Text Text
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 :: (Text -> f Text) -> OpenSearchAction -> f OpenSearchAction
openSearchAction_endpoint = (OpenSearchAction -> Text)
-> (OpenSearchAction -> Text -> OpenSearchAction)
-> Lens OpenSearchAction OpenSearchAction Text Text
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 :: (Text -> f Text) -> OpenSearchAction -> f OpenSearchAction
openSearchAction_index = (OpenSearchAction -> Text)
-> (OpenSearchAction -> Text -> OpenSearchAction)
-> Lens OpenSearchAction OpenSearchAction Text Text
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 :: (Text -> f Text) -> OpenSearchAction -> f OpenSearchAction
openSearchAction_type = (OpenSearchAction -> Text)
-> (OpenSearchAction -> Text -> OpenSearchAction)
-> Lens OpenSearchAction OpenSearchAction Text Text
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 :: (Text -> f Text) -> OpenSearchAction -> f OpenSearchAction
openSearchAction_id = (OpenSearchAction -> Text)
-> (OpenSearchAction -> Text -> OpenSearchAction)
-> Lens OpenSearchAction OpenSearchAction Text Text
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 Core.FromJSON OpenSearchAction where
  parseJSON :: Value -> Parser OpenSearchAction
parseJSON =
    String
-> (Object -> Parser OpenSearchAction)
-> Value
-> Parser OpenSearchAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"OpenSearchAction"
      ( \Object
x ->
          Text -> Text -> Text -> Text -> Text -> OpenSearchAction
OpenSearchAction'
            (Text -> Text -> Text -> Text -> Text -> OpenSearchAction)
-> Parser Text
-> Parser (Text -> Text -> Text -> Text -> OpenSearchAction)
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 -> OpenSearchAction)
-> Parser Text -> Parser (Text -> Text -> Text -> OpenSearchAction)
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 -> OpenSearchAction)
-> Parser Text -> Parser (Text -> Text -> OpenSearchAction)
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 -> OpenSearchAction)
-> Parser Text -> Parser (Text -> OpenSearchAction)
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 -> OpenSearchAction)
-> Parser Text -> Parser OpenSearchAction
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 OpenSearchAction

instance Prelude.NFData OpenSearchAction

instance Core.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
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)
          ]
      )