{-# 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.FirehoseAction
-- 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.FirehoseAction 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 Kinesis Firehose
-- stream.
--
-- /See:/ 'newFirehoseAction' smart constructor.
data FirehoseAction = FirehoseAction'
  { -- | Whether to deliver the Kinesis Data Firehose stream as a batch by using
    -- <https://docs.aws.amazon.com/firehose/latest/APIReference/API_PutRecordBatch.html PutRecordBatch>
    -- . The default value is @false@.
    --
    -- When @batchMode@ is @true@ and the rule\'s SQL statement evaluates to an
    -- Array, each Array element forms one record in the
    -- <https://docs.aws.amazon.com/firehose/latest/APIReference/API_PutRecordBatch.html PutRecordBatch>
    -- request. The resulting array can\'t have more than 500 records.
    FirehoseAction -> Maybe Bool
batchMode :: Prelude.Maybe Prelude.Bool,
    -- | A character separator that will be used to separate records written to
    -- the Firehose stream. Valid values are: \'\\n\' (newline), \'\\t\' (tab),
    -- \'\\r\\n\' (Windows newline), \',\' (comma).
    FirehoseAction -> Maybe Text
separator :: Prelude.Maybe Prelude.Text,
    -- | The IAM role that grants access to the Amazon Kinesis Firehose stream.
    FirehoseAction -> Text
roleArn :: Prelude.Text,
    -- | The delivery stream name.
    FirehoseAction -> Text
deliveryStreamName :: Prelude.Text
  }
  deriving (FirehoseAction -> FirehoseAction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FirehoseAction -> FirehoseAction -> Bool
$c/= :: FirehoseAction -> FirehoseAction -> Bool
== :: FirehoseAction -> FirehoseAction -> Bool
$c== :: FirehoseAction -> FirehoseAction -> Bool
Prelude.Eq, ReadPrec [FirehoseAction]
ReadPrec FirehoseAction
Int -> ReadS FirehoseAction
ReadS [FirehoseAction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FirehoseAction]
$creadListPrec :: ReadPrec [FirehoseAction]
readPrec :: ReadPrec FirehoseAction
$creadPrec :: ReadPrec FirehoseAction
readList :: ReadS [FirehoseAction]
$creadList :: ReadS [FirehoseAction]
readsPrec :: Int -> ReadS FirehoseAction
$creadsPrec :: Int -> ReadS FirehoseAction
Prelude.Read, Int -> FirehoseAction -> ShowS
[FirehoseAction] -> ShowS
FirehoseAction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FirehoseAction] -> ShowS
$cshowList :: [FirehoseAction] -> ShowS
show :: FirehoseAction -> String
$cshow :: FirehoseAction -> String
showsPrec :: Int -> FirehoseAction -> ShowS
$cshowsPrec :: Int -> FirehoseAction -> ShowS
Prelude.Show, forall x. Rep FirehoseAction x -> FirehoseAction
forall x. FirehoseAction -> Rep FirehoseAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FirehoseAction x -> FirehoseAction
$cfrom :: forall x. FirehoseAction -> Rep FirehoseAction x
Prelude.Generic)

-- |
-- Create a value of 'FirehoseAction' 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:
--
-- 'batchMode', 'firehoseAction_batchMode' - Whether to deliver the Kinesis Data Firehose stream as a batch by using
-- <https://docs.aws.amazon.com/firehose/latest/APIReference/API_PutRecordBatch.html PutRecordBatch>
-- . The default value is @false@.
--
-- When @batchMode@ is @true@ and the rule\'s SQL statement evaluates to an
-- Array, each Array element forms one record in the
-- <https://docs.aws.amazon.com/firehose/latest/APIReference/API_PutRecordBatch.html PutRecordBatch>
-- request. The resulting array can\'t have more than 500 records.
--
-- 'separator', 'firehoseAction_separator' - A character separator that will be used to separate records written to
-- the Firehose stream. Valid values are: \'\\n\' (newline), \'\\t\' (tab),
-- \'\\r\\n\' (Windows newline), \',\' (comma).
--
-- 'roleArn', 'firehoseAction_roleArn' - The IAM role that grants access to the Amazon Kinesis Firehose stream.
--
-- 'deliveryStreamName', 'firehoseAction_deliveryStreamName' - The delivery stream name.
newFirehoseAction ::
  -- | 'roleArn'
  Prelude.Text ->
  -- | 'deliveryStreamName'
  Prelude.Text ->
  FirehoseAction
newFirehoseAction :: Text -> Text -> FirehoseAction
newFirehoseAction Text
pRoleArn_ Text
pDeliveryStreamName_ =
  FirehoseAction'
    { $sel:batchMode:FirehoseAction' :: Maybe Bool
batchMode = forall a. Maybe a
Prelude.Nothing,
      $sel:separator:FirehoseAction' :: Maybe Text
separator = forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:FirehoseAction' :: Text
roleArn = Text
pRoleArn_,
      $sel:deliveryStreamName:FirehoseAction' :: Text
deliveryStreamName = Text
pDeliveryStreamName_
    }

-- | Whether to deliver the Kinesis Data Firehose stream as a batch by using
-- <https://docs.aws.amazon.com/firehose/latest/APIReference/API_PutRecordBatch.html PutRecordBatch>
-- . The default value is @false@.
--
-- When @batchMode@ is @true@ and the rule\'s SQL statement evaluates to an
-- Array, each Array element forms one record in the
-- <https://docs.aws.amazon.com/firehose/latest/APIReference/API_PutRecordBatch.html PutRecordBatch>
-- request. The resulting array can\'t have more than 500 records.
firehoseAction_batchMode :: Lens.Lens' FirehoseAction (Prelude.Maybe Prelude.Bool)
firehoseAction_batchMode :: Lens' FirehoseAction (Maybe Bool)
firehoseAction_batchMode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FirehoseAction' {Maybe Bool
batchMode :: Maybe Bool
$sel:batchMode:FirehoseAction' :: FirehoseAction -> Maybe Bool
batchMode} -> Maybe Bool
batchMode) (\s :: FirehoseAction
s@FirehoseAction' {} Maybe Bool
a -> FirehoseAction
s {$sel:batchMode:FirehoseAction' :: Maybe Bool
batchMode = Maybe Bool
a} :: FirehoseAction)

-- | A character separator that will be used to separate records written to
-- the Firehose stream. Valid values are: \'\\n\' (newline), \'\\t\' (tab),
-- \'\\r\\n\' (Windows newline), \',\' (comma).
firehoseAction_separator :: Lens.Lens' FirehoseAction (Prelude.Maybe Prelude.Text)
firehoseAction_separator :: Lens' FirehoseAction (Maybe Text)
firehoseAction_separator = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FirehoseAction' {Maybe Text
separator :: Maybe Text
$sel:separator:FirehoseAction' :: FirehoseAction -> Maybe Text
separator} -> Maybe Text
separator) (\s :: FirehoseAction
s@FirehoseAction' {} Maybe Text
a -> FirehoseAction
s {$sel:separator:FirehoseAction' :: Maybe Text
separator = Maybe Text
a} :: FirehoseAction)

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

-- | The delivery stream name.
firehoseAction_deliveryStreamName :: Lens.Lens' FirehoseAction Prelude.Text
firehoseAction_deliveryStreamName :: Lens' FirehoseAction Text
firehoseAction_deliveryStreamName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FirehoseAction' {Text
deliveryStreamName :: Text
$sel:deliveryStreamName:FirehoseAction' :: FirehoseAction -> Text
deliveryStreamName} -> Text
deliveryStreamName) (\s :: FirehoseAction
s@FirehoseAction' {} Text
a -> FirehoseAction
s {$sel:deliveryStreamName:FirehoseAction' :: Text
deliveryStreamName = Text
a} :: FirehoseAction)

instance Data.FromJSON FirehoseAction where
  parseJSON :: Value -> Parser FirehoseAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FirehoseAction"
      ( \Object
x ->
          Maybe Bool -> Maybe Text -> Text -> Text -> FirehoseAction
FirehoseAction'
            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
"batchMode")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"separator")
            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
"deliveryStreamName")
      )

instance Prelude.Hashable FirehoseAction where
  hashWithSalt :: Int -> FirehoseAction -> Int
hashWithSalt Int
_salt FirehoseAction' {Maybe Bool
Maybe Text
Text
deliveryStreamName :: Text
roleArn :: Text
separator :: Maybe Text
batchMode :: Maybe Bool
$sel:deliveryStreamName:FirehoseAction' :: FirehoseAction -> Text
$sel:roleArn:FirehoseAction' :: FirehoseAction -> Text
$sel:separator:FirehoseAction' :: FirehoseAction -> Maybe Text
$sel:batchMode:FirehoseAction' :: FirehoseAction -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
batchMode
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
separator
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
roleArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
deliveryStreamName

instance Prelude.NFData FirehoseAction where
  rnf :: FirehoseAction -> ()
rnf FirehoseAction' {Maybe Bool
Maybe Text
Text
deliveryStreamName :: Text
roleArn :: Text
separator :: Maybe Text
batchMode :: Maybe Bool
$sel:deliveryStreamName:FirehoseAction' :: FirehoseAction -> Text
$sel:roleArn:FirehoseAction' :: FirehoseAction -> Text
$sel:separator:FirehoseAction' :: FirehoseAction -> Maybe Text
$sel:batchMode:FirehoseAction' :: FirehoseAction -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
batchMode
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
separator
      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
deliveryStreamName

instance Data.ToJSON FirehoseAction where
  toJSON :: FirehoseAction -> Value
toJSON FirehoseAction' {Maybe Bool
Maybe Text
Text
deliveryStreamName :: Text
roleArn :: Text
separator :: Maybe Text
batchMode :: Maybe Bool
$sel:deliveryStreamName:FirehoseAction' :: FirehoseAction -> Text
$sel:roleArn:FirehoseAction' :: FirehoseAction -> Text
$sel:separator:FirehoseAction' :: FirehoseAction -> Maybe Text
$sel:batchMode:FirehoseAction' :: FirehoseAction -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"batchMode" 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 Bool
batchMode,
            (Key
"separator" 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
separator,
            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
"deliveryStreamName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
deliveryStreamName)
          ]
      )