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

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

-- | Describes an action to write data to an Amazon Kinesis stream.
--
-- /See:/ 'newKinesisAction' smart constructor.
data KinesisAction = KinesisAction'
  { -- | The partition key.
    KinesisAction -> Maybe Text
partitionKey :: Prelude.Maybe Prelude.Text,
    -- | The ARN of the IAM role that grants access to the Amazon Kinesis stream.
    KinesisAction -> Text
roleArn :: Prelude.Text,
    -- | The name of the Amazon Kinesis stream.
    KinesisAction -> Text
streamName :: Prelude.Text
  }
  deriving (KinesisAction -> KinesisAction -> Bool
(KinesisAction -> KinesisAction -> Bool)
-> (KinesisAction -> KinesisAction -> Bool) -> Eq KinesisAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: KinesisAction -> KinesisAction -> Bool
$c/= :: KinesisAction -> KinesisAction -> Bool
== :: KinesisAction -> KinesisAction -> Bool
$c== :: KinesisAction -> KinesisAction -> Bool
Prelude.Eq, ReadPrec [KinesisAction]
ReadPrec KinesisAction
Int -> ReadS KinesisAction
ReadS [KinesisAction]
(Int -> ReadS KinesisAction)
-> ReadS [KinesisAction]
-> ReadPrec KinesisAction
-> ReadPrec [KinesisAction]
-> Read KinesisAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [KinesisAction]
$creadListPrec :: ReadPrec [KinesisAction]
readPrec :: ReadPrec KinesisAction
$creadPrec :: ReadPrec KinesisAction
readList :: ReadS [KinesisAction]
$creadList :: ReadS [KinesisAction]
readsPrec :: Int -> ReadS KinesisAction
$creadsPrec :: Int -> ReadS KinesisAction
Prelude.Read, Int -> KinesisAction -> ShowS
[KinesisAction] -> ShowS
KinesisAction -> String
(Int -> KinesisAction -> ShowS)
-> (KinesisAction -> String)
-> ([KinesisAction] -> ShowS)
-> Show KinesisAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [KinesisAction] -> ShowS
$cshowList :: [KinesisAction] -> ShowS
show :: KinesisAction -> String
$cshow :: KinesisAction -> String
showsPrec :: Int -> KinesisAction -> ShowS
$cshowsPrec :: Int -> KinesisAction -> ShowS
Prelude.Show, (forall x. KinesisAction -> Rep KinesisAction x)
-> (forall x. Rep KinesisAction x -> KinesisAction)
-> Generic KinesisAction
forall x. Rep KinesisAction x -> KinesisAction
forall x. KinesisAction -> Rep KinesisAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep KinesisAction x -> KinesisAction
$cfrom :: forall x. KinesisAction -> Rep KinesisAction x
Prelude.Generic)

-- |
-- Create a value of 'KinesisAction' 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:
--
-- 'partitionKey', 'kinesisAction_partitionKey' - The partition key.
--
-- 'roleArn', 'kinesisAction_roleArn' - The ARN of the IAM role that grants access to the Amazon Kinesis stream.
--
-- 'streamName', 'kinesisAction_streamName' - The name of the Amazon Kinesis stream.
newKinesisAction ::
  -- | 'roleArn'
  Prelude.Text ->
  -- | 'streamName'
  Prelude.Text ->
  KinesisAction
newKinesisAction :: Text -> Text -> KinesisAction
newKinesisAction Text
pRoleArn_ Text
pStreamName_ =
  KinesisAction' :: Maybe Text -> Text -> Text -> KinesisAction
KinesisAction'
    { $sel:partitionKey:KinesisAction' :: Maybe Text
partitionKey = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:KinesisAction' :: Text
roleArn = Text
pRoleArn_,
      $sel:streamName:KinesisAction' :: Text
streamName = Text
pStreamName_
    }

-- | The partition key.
kinesisAction_partitionKey :: Lens.Lens' KinesisAction (Prelude.Maybe Prelude.Text)
kinesisAction_partitionKey :: (Maybe Text -> f (Maybe Text)) -> KinesisAction -> f KinesisAction
kinesisAction_partitionKey = (KinesisAction -> Maybe Text)
-> (KinesisAction -> Maybe Text -> KinesisAction)
-> Lens KinesisAction KinesisAction (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KinesisAction' {Maybe Text
partitionKey :: Maybe Text
$sel:partitionKey:KinesisAction' :: KinesisAction -> Maybe Text
partitionKey} -> Maybe Text
partitionKey) (\s :: KinesisAction
s@KinesisAction' {} Maybe Text
a -> KinesisAction
s {$sel:partitionKey:KinesisAction' :: Maybe Text
partitionKey = Maybe Text
a} :: KinesisAction)

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

-- | The name of the Amazon Kinesis stream.
kinesisAction_streamName :: Lens.Lens' KinesisAction Prelude.Text
kinesisAction_streamName :: (Text -> f Text) -> KinesisAction -> f KinesisAction
kinesisAction_streamName = (KinesisAction -> Text)
-> (KinesisAction -> Text -> KinesisAction)
-> Lens KinesisAction KinesisAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KinesisAction' {Text
streamName :: Text
$sel:streamName:KinesisAction' :: KinesisAction -> Text
streamName} -> Text
streamName) (\s :: KinesisAction
s@KinesisAction' {} Text
a -> KinesisAction
s {$sel:streamName:KinesisAction' :: Text
streamName = Text
a} :: KinesisAction)

instance Core.FromJSON KinesisAction where
  parseJSON :: Value -> Parser KinesisAction
parseJSON =
    String
-> (Object -> Parser KinesisAction)
-> Value
-> Parser KinesisAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"KinesisAction"
      ( \Object
x ->
          Maybe Text -> Text -> Text -> KinesisAction
KinesisAction'
            (Maybe Text -> Text -> Text -> KinesisAction)
-> Parser (Maybe Text) -> Parser (Text -> Text -> KinesisAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"partitionKey")
            Parser (Text -> Text -> KinesisAction)
-> Parser Text -> Parser (Text -> KinesisAction)
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
"roleArn")
            Parser (Text -> KinesisAction)
-> Parser Text -> Parser KinesisAction
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
"streamName")
      )

instance Prelude.Hashable KinesisAction

instance Prelude.NFData KinesisAction

instance Core.ToJSON KinesisAction where
  toJSON :: KinesisAction -> Value
toJSON KinesisAction' {Maybe Text
Text
streamName :: Text
roleArn :: Text
partitionKey :: Maybe Text
$sel:streamName:KinesisAction' :: KinesisAction -> Text
$sel:roleArn:KinesisAction' :: KinesisAction -> Text
$sel:partitionKey:KinesisAction' :: KinesisAction -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"partitionKey" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
partitionKey,
            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
"streamName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
streamName)
          ]
      )