{-# 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.KafkaAction
-- 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.KafkaAction 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

-- | Send messages to an Amazon Managed Streaming for Apache Kafka (Amazon
-- MSK) or self-managed Apache Kafka cluster.
--
-- /See:/ 'newKafkaAction' smart constructor.
data KafkaAction = KafkaAction'
  { -- | The Kafka message key.
    KafkaAction -> Maybe Text
key :: Prelude.Maybe Prelude.Text,
    -- | The Kafka message partition.
    KafkaAction -> Maybe Text
partition :: Prelude.Maybe Prelude.Text,
    -- | The ARN of Kafka action\'s VPC @TopicRuleDestination@.
    KafkaAction -> Text
destinationArn :: Prelude.Text,
    -- | The Kafka topic for messages to be sent to the Kafka broker.
    KafkaAction -> Text
topic :: Prelude.Text,
    -- | Properties of the Apache Kafka producer client.
    KafkaAction -> HashMap Text Text
clientProperties :: Prelude.HashMap Prelude.Text Prelude.Text
  }
  deriving (KafkaAction -> KafkaAction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: KafkaAction -> KafkaAction -> Bool
$c/= :: KafkaAction -> KafkaAction -> Bool
== :: KafkaAction -> KafkaAction -> Bool
$c== :: KafkaAction -> KafkaAction -> Bool
Prelude.Eq, ReadPrec [KafkaAction]
ReadPrec KafkaAction
Int -> ReadS KafkaAction
ReadS [KafkaAction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [KafkaAction]
$creadListPrec :: ReadPrec [KafkaAction]
readPrec :: ReadPrec KafkaAction
$creadPrec :: ReadPrec KafkaAction
readList :: ReadS [KafkaAction]
$creadList :: ReadS [KafkaAction]
readsPrec :: Int -> ReadS KafkaAction
$creadsPrec :: Int -> ReadS KafkaAction
Prelude.Read, Int -> KafkaAction -> ShowS
[KafkaAction] -> ShowS
KafkaAction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [KafkaAction] -> ShowS
$cshowList :: [KafkaAction] -> ShowS
show :: KafkaAction -> String
$cshow :: KafkaAction -> String
showsPrec :: Int -> KafkaAction -> ShowS
$cshowsPrec :: Int -> KafkaAction -> ShowS
Prelude.Show, forall x. Rep KafkaAction x -> KafkaAction
forall x. KafkaAction -> Rep KafkaAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep KafkaAction x -> KafkaAction
$cfrom :: forall x. KafkaAction -> Rep KafkaAction x
Prelude.Generic)

-- |
-- Create a value of 'KafkaAction' 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:
--
-- 'key', 'kafkaAction_key' - The Kafka message key.
--
-- 'partition', 'kafkaAction_partition' - The Kafka message partition.
--
-- 'destinationArn', 'kafkaAction_destinationArn' - The ARN of Kafka action\'s VPC @TopicRuleDestination@.
--
-- 'topic', 'kafkaAction_topic' - The Kafka topic for messages to be sent to the Kafka broker.
--
-- 'clientProperties', 'kafkaAction_clientProperties' - Properties of the Apache Kafka producer client.
newKafkaAction ::
  -- | 'destinationArn'
  Prelude.Text ->
  -- | 'topic'
  Prelude.Text ->
  KafkaAction
newKafkaAction :: Text -> Text -> KafkaAction
newKafkaAction Text
pDestinationArn_ Text
pTopic_ =
  KafkaAction'
    { $sel:key:KafkaAction' :: Maybe Text
key = forall a. Maybe a
Prelude.Nothing,
      $sel:partition:KafkaAction' :: Maybe Text
partition = forall a. Maybe a
Prelude.Nothing,
      $sel:destinationArn:KafkaAction' :: Text
destinationArn = Text
pDestinationArn_,
      $sel:topic:KafkaAction' :: Text
topic = Text
pTopic_,
      $sel:clientProperties:KafkaAction' :: HashMap Text Text
clientProperties = forall a. Monoid a => a
Prelude.mempty
    }

-- | The Kafka message key.
kafkaAction_key :: Lens.Lens' KafkaAction (Prelude.Maybe Prelude.Text)
kafkaAction_key :: Lens' KafkaAction (Maybe Text)
kafkaAction_key = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KafkaAction' {Maybe Text
key :: Maybe Text
$sel:key:KafkaAction' :: KafkaAction -> Maybe Text
key} -> Maybe Text
key) (\s :: KafkaAction
s@KafkaAction' {} Maybe Text
a -> KafkaAction
s {$sel:key:KafkaAction' :: Maybe Text
key = Maybe Text
a} :: KafkaAction)

-- | The Kafka message partition.
kafkaAction_partition :: Lens.Lens' KafkaAction (Prelude.Maybe Prelude.Text)
kafkaAction_partition :: Lens' KafkaAction (Maybe Text)
kafkaAction_partition = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KafkaAction' {Maybe Text
partition :: Maybe Text
$sel:partition:KafkaAction' :: KafkaAction -> Maybe Text
partition} -> Maybe Text
partition) (\s :: KafkaAction
s@KafkaAction' {} Maybe Text
a -> KafkaAction
s {$sel:partition:KafkaAction' :: Maybe Text
partition = Maybe Text
a} :: KafkaAction)

-- | The ARN of Kafka action\'s VPC @TopicRuleDestination@.
kafkaAction_destinationArn :: Lens.Lens' KafkaAction Prelude.Text
kafkaAction_destinationArn :: Lens' KafkaAction Text
kafkaAction_destinationArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KafkaAction' {Text
destinationArn :: Text
$sel:destinationArn:KafkaAction' :: KafkaAction -> Text
destinationArn} -> Text
destinationArn) (\s :: KafkaAction
s@KafkaAction' {} Text
a -> KafkaAction
s {$sel:destinationArn:KafkaAction' :: Text
destinationArn = Text
a} :: KafkaAction)

-- | The Kafka topic for messages to be sent to the Kafka broker.
kafkaAction_topic :: Lens.Lens' KafkaAction Prelude.Text
kafkaAction_topic :: Lens' KafkaAction Text
kafkaAction_topic = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KafkaAction' {Text
topic :: Text
$sel:topic:KafkaAction' :: KafkaAction -> Text
topic} -> Text
topic) (\s :: KafkaAction
s@KafkaAction' {} Text
a -> KafkaAction
s {$sel:topic:KafkaAction' :: Text
topic = Text
a} :: KafkaAction)

-- | Properties of the Apache Kafka producer client.
kafkaAction_clientProperties :: Lens.Lens' KafkaAction (Prelude.HashMap Prelude.Text Prelude.Text)
kafkaAction_clientProperties :: Lens' KafkaAction (HashMap Text Text)
kafkaAction_clientProperties = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KafkaAction' {HashMap Text Text
clientProperties :: HashMap Text Text
$sel:clientProperties:KafkaAction' :: KafkaAction -> HashMap Text Text
clientProperties} -> HashMap Text Text
clientProperties) (\s :: KafkaAction
s@KafkaAction' {} HashMap Text Text
a -> KafkaAction
s {$sel:clientProperties:KafkaAction' :: HashMap Text Text
clientProperties = HashMap Text Text
a} :: KafkaAction) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON KafkaAction where
  parseJSON :: Value -> Parser KafkaAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"KafkaAction"
      ( \Object
x ->
          Maybe Text
-> Maybe Text -> Text -> Text -> HashMap Text Text -> KafkaAction
KafkaAction'
            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
"key")
            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
"partition")
            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
"destinationArn")
            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
"topic")
            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
"clientProperties"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable KafkaAction where
  hashWithSalt :: Int -> KafkaAction -> Int
hashWithSalt Int
_salt KafkaAction' {Maybe Text
Text
HashMap Text Text
clientProperties :: HashMap Text Text
topic :: Text
destinationArn :: Text
partition :: Maybe Text
key :: Maybe Text
$sel:clientProperties:KafkaAction' :: KafkaAction -> HashMap Text Text
$sel:topic:KafkaAction' :: KafkaAction -> Text
$sel:destinationArn:KafkaAction' :: KafkaAction -> Text
$sel:partition:KafkaAction' :: KafkaAction -> Maybe Text
$sel:key:KafkaAction' :: KafkaAction -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
key
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
partition
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
destinationArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
topic
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` HashMap Text Text
clientProperties

instance Prelude.NFData KafkaAction where
  rnf :: KafkaAction -> ()
rnf KafkaAction' {Maybe Text
Text
HashMap Text Text
clientProperties :: HashMap Text Text
topic :: Text
destinationArn :: Text
partition :: Maybe Text
key :: Maybe Text
$sel:clientProperties:KafkaAction' :: KafkaAction -> HashMap Text Text
$sel:topic:KafkaAction' :: KafkaAction -> Text
$sel:destinationArn:KafkaAction' :: KafkaAction -> Text
$sel:partition:KafkaAction' :: KafkaAction -> Maybe Text
$sel:key:KafkaAction' :: KafkaAction -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
key
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
partition
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
destinationArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
topic
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf HashMap Text Text
clientProperties

instance Data.ToJSON KafkaAction where
  toJSON :: KafkaAction -> Value
toJSON KafkaAction' {Maybe Text
Text
HashMap Text Text
clientProperties :: HashMap Text Text
topic :: Text
destinationArn :: Text
partition :: Maybe Text
key :: Maybe Text
$sel:clientProperties:KafkaAction' :: KafkaAction -> HashMap Text Text
$sel:topic:KafkaAction' :: KafkaAction -> Text
$sel:destinationArn:KafkaAction' :: KafkaAction -> Text
$sel:partition:KafkaAction' :: KafkaAction -> Maybe Text
$sel:key:KafkaAction' :: KafkaAction -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"key" 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
key,
            (Key
"partition" 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
partition,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"destinationArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
destinationArn),
            forall a. a -> Maybe a
Prelude.Just (Key
"topic" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
topic),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"clientProperties" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= HashMap Text Text
clientProperties)
          ]
      )