{-# 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.DynamoDBv2Action
-- 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.DynamoDBv2Action where

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.PutItemInput
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes an action to write to a DynamoDB table.
--
-- This DynamoDB action writes each attribute in the message payload into
-- it\'s own column in the DynamoDB table.
--
-- /See:/ 'newDynamoDBv2Action' smart constructor.
data DynamoDBv2Action = DynamoDBv2Action'
  { -- | The ARN of the IAM role that grants access to the DynamoDB table.
    DynamoDBv2Action -> Text
roleArn :: Prelude.Text,
    -- | Specifies the DynamoDB table to which the message data will be written.
    -- For example:
    --
    -- @{ \"dynamoDBv2\": { \"roleArn\": \"aws:iam:12341251:my-role\" \"putItem\": { \"tableName\": \"my-table\" } } }@
    --
    -- Each attribute in the message payload will be written to a separate
    -- column in the DynamoDB database.
    DynamoDBv2Action -> PutItemInput
putItem :: PutItemInput
  }
  deriving (DynamoDBv2Action -> DynamoDBv2Action -> Bool
(DynamoDBv2Action -> DynamoDBv2Action -> Bool)
-> (DynamoDBv2Action -> DynamoDBv2Action -> Bool)
-> Eq DynamoDBv2Action
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DynamoDBv2Action -> DynamoDBv2Action -> Bool
$c/= :: DynamoDBv2Action -> DynamoDBv2Action -> Bool
== :: DynamoDBv2Action -> DynamoDBv2Action -> Bool
$c== :: DynamoDBv2Action -> DynamoDBv2Action -> Bool
Prelude.Eq, ReadPrec [DynamoDBv2Action]
ReadPrec DynamoDBv2Action
Int -> ReadS DynamoDBv2Action
ReadS [DynamoDBv2Action]
(Int -> ReadS DynamoDBv2Action)
-> ReadS [DynamoDBv2Action]
-> ReadPrec DynamoDBv2Action
-> ReadPrec [DynamoDBv2Action]
-> Read DynamoDBv2Action
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DynamoDBv2Action]
$creadListPrec :: ReadPrec [DynamoDBv2Action]
readPrec :: ReadPrec DynamoDBv2Action
$creadPrec :: ReadPrec DynamoDBv2Action
readList :: ReadS [DynamoDBv2Action]
$creadList :: ReadS [DynamoDBv2Action]
readsPrec :: Int -> ReadS DynamoDBv2Action
$creadsPrec :: Int -> ReadS DynamoDBv2Action
Prelude.Read, Int -> DynamoDBv2Action -> ShowS
[DynamoDBv2Action] -> ShowS
DynamoDBv2Action -> String
(Int -> DynamoDBv2Action -> ShowS)
-> (DynamoDBv2Action -> String)
-> ([DynamoDBv2Action] -> ShowS)
-> Show DynamoDBv2Action
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DynamoDBv2Action] -> ShowS
$cshowList :: [DynamoDBv2Action] -> ShowS
show :: DynamoDBv2Action -> String
$cshow :: DynamoDBv2Action -> String
showsPrec :: Int -> DynamoDBv2Action -> ShowS
$cshowsPrec :: Int -> DynamoDBv2Action -> ShowS
Prelude.Show, (forall x. DynamoDBv2Action -> Rep DynamoDBv2Action x)
-> (forall x. Rep DynamoDBv2Action x -> DynamoDBv2Action)
-> Generic DynamoDBv2Action
forall x. Rep DynamoDBv2Action x -> DynamoDBv2Action
forall x. DynamoDBv2Action -> Rep DynamoDBv2Action x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DynamoDBv2Action x -> DynamoDBv2Action
$cfrom :: forall x. DynamoDBv2Action -> Rep DynamoDBv2Action x
Prelude.Generic)

-- |
-- Create a value of 'DynamoDBv2Action' 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', 'dynamoDBv2Action_roleArn' - The ARN of the IAM role that grants access to the DynamoDB table.
--
-- 'putItem', 'dynamoDBv2Action_putItem' - Specifies the DynamoDB table to which the message data will be written.
-- For example:
--
-- @{ \"dynamoDBv2\": { \"roleArn\": \"aws:iam:12341251:my-role\" \"putItem\": { \"tableName\": \"my-table\" } } }@
--
-- Each attribute in the message payload will be written to a separate
-- column in the DynamoDB database.
newDynamoDBv2Action ::
  -- | 'roleArn'
  Prelude.Text ->
  -- | 'putItem'
  PutItemInput ->
  DynamoDBv2Action
newDynamoDBv2Action :: Text -> PutItemInput -> DynamoDBv2Action
newDynamoDBv2Action Text
pRoleArn_ PutItemInput
pPutItem_ =
  DynamoDBv2Action' :: Text -> PutItemInput -> DynamoDBv2Action
DynamoDBv2Action'
    { $sel:roleArn:DynamoDBv2Action' :: Text
roleArn = Text
pRoleArn_,
      $sel:putItem:DynamoDBv2Action' :: PutItemInput
putItem = PutItemInput
pPutItem_
    }

-- | The ARN of the IAM role that grants access to the DynamoDB table.
dynamoDBv2Action_roleArn :: Lens.Lens' DynamoDBv2Action Prelude.Text
dynamoDBv2Action_roleArn :: (Text -> f Text) -> DynamoDBv2Action -> f DynamoDBv2Action
dynamoDBv2Action_roleArn = (DynamoDBv2Action -> Text)
-> (DynamoDBv2Action -> Text -> DynamoDBv2Action)
-> Lens DynamoDBv2Action DynamoDBv2Action Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DynamoDBv2Action' {Text
roleArn :: Text
$sel:roleArn:DynamoDBv2Action' :: DynamoDBv2Action -> Text
roleArn} -> Text
roleArn) (\s :: DynamoDBv2Action
s@DynamoDBv2Action' {} Text
a -> DynamoDBv2Action
s {$sel:roleArn:DynamoDBv2Action' :: Text
roleArn = Text
a} :: DynamoDBv2Action)

-- | Specifies the DynamoDB table to which the message data will be written.
-- For example:
--
-- @{ \"dynamoDBv2\": { \"roleArn\": \"aws:iam:12341251:my-role\" \"putItem\": { \"tableName\": \"my-table\" } } }@
--
-- Each attribute in the message payload will be written to a separate
-- column in the DynamoDB database.
dynamoDBv2Action_putItem :: Lens.Lens' DynamoDBv2Action PutItemInput
dynamoDBv2Action_putItem :: (PutItemInput -> f PutItemInput)
-> DynamoDBv2Action -> f DynamoDBv2Action
dynamoDBv2Action_putItem = (DynamoDBv2Action -> PutItemInput)
-> (DynamoDBv2Action -> PutItemInput -> DynamoDBv2Action)
-> Lens DynamoDBv2Action DynamoDBv2Action PutItemInput PutItemInput
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DynamoDBv2Action' {PutItemInput
putItem :: PutItemInput
$sel:putItem:DynamoDBv2Action' :: DynamoDBv2Action -> PutItemInput
putItem} -> PutItemInput
putItem) (\s :: DynamoDBv2Action
s@DynamoDBv2Action' {} PutItemInput
a -> DynamoDBv2Action
s {$sel:putItem:DynamoDBv2Action' :: PutItemInput
putItem = PutItemInput
a} :: DynamoDBv2Action)

instance Core.FromJSON DynamoDBv2Action where
  parseJSON :: Value -> Parser DynamoDBv2Action
parseJSON =
    String
-> (Object -> Parser DynamoDBv2Action)
-> Value
-> Parser DynamoDBv2Action
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DynamoDBv2Action"
      ( \Object
x ->
          Text -> PutItemInput -> DynamoDBv2Action
DynamoDBv2Action'
            (Text -> PutItemInput -> DynamoDBv2Action)
-> Parser Text -> Parser (PutItemInput -> DynamoDBv2Action)
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 (PutItemInput -> DynamoDBv2Action)
-> Parser PutItemInput -> Parser DynamoDBv2Action
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser PutItemInput
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"putItem")
      )

instance Prelude.Hashable DynamoDBv2Action

instance Prelude.NFData DynamoDBv2Action

instance Core.ToJSON DynamoDBv2Action where
  toJSON :: DynamoDBv2Action -> Value
toJSON DynamoDBv2Action' {Text
PutItemInput
putItem :: PutItemInput
roleArn :: Text
$sel:putItem:DynamoDBv2Action' :: DynamoDBv2Action -> PutItemInput
$sel:roleArn:DynamoDBv2Action' :: DynamoDBv2Action -> 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
"putItem" Text -> PutItemInput -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PutItemInput
putItem)
          ]
      )