{-# 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-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.KinesisAction 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 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
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]
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
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. 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'
    { $sel:partitionKey:KinesisAction' :: Maybe Text
partitionKey = 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 :: Lens' KinesisAction (Maybe Text)
kinesisAction_partitionKey = 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 :: Lens' KinesisAction Text
kinesisAction_roleArn = 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 :: Lens' KinesisAction Text
kinesisAction_streamName = 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 Data.FromJSON KinesisAction where
  parseJSON :: Value -> Parser KinesisAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"KinesisAction"
      ( \Object
x ->
          Maybe Text -> Text -> Text -> KinesisAction
KinesisAction'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"partitionKey")
            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
"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
"streamName")
      )

instance Prelude.Hashable KinesisAction where
  hashWithSalt :: Int -> KinesisAction -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
partitionKey
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
roleArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
streamName

instance Prelude.NFData KinesisAction where
  rnf :: KinesisAction -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
partitionKey
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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
streamName

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"partitionKey" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
partitionKey,
            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
"streamName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
streamName)
          ]
      )