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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(KafkaAction -> KafkaAction -> Bool)
-> (KafkaAction -> KafkaAction -> Bool) -> Eq KafkaAction
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]
(Int -> ReadS KafkaAction)
-> ReadS [KafkaAction]
-> ReadPrec KafkaAction
-> ReadPrec [KafkaAction]
-> Read 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
(Int -> KafkaAction -> ShowS)
-> (KafkaAction -> String)
-> ([KafkaAction] -> ShowS)
-> Show KafkaAction
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. KafkaAction -> Rep KafkaAction x)
-> (forall x. Rep KafkaAction x -> KafkaAction)
-> Generic KafkaAction
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' :: Maybe Text
-> Maybe Text -> Text -> Text -> HashMap Text Text -> KafkaAction
KafkaAction'
    { $sel:key:KafkaAction' :: Maybe Text
key = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:partition:KafkaAction' :: Maybe Text
partition = Maybe Text
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 = HashMap Text Text
forall a. Monoid a => a
Prelude.mempty
    }

-- | The Kafka message key.
kafkaAction_key :: Lens.Lens' KafkaAction (Prelude.Maybe Prelude.Text)
kafkaAction_key :: (Maybe Text -> f (Maybe Text)) -> KafkaAction -> f KafkaAction
kafkaAction_key = (KafkaAction -> Maybe Text)
-> (KafkaAction -> Maybe Text -> KafkaAction)
-> Lens KafkaAction KafkaAction (Maybe Text) (Maybe Text)
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 :: (Maybe Text -> f (Maybe Text)) -> KafkaAction -> f KafkaAction
kafkaAction_partition = (KafkaAction -> Maybe Text)
-> (KafkaAction -> Maybe Text -> KafkaAction)
-> Lens KafkaAction KafkaAction (Maybe Text) (Maybe Text)
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 :: (Text -> f Text) -> KafkaAction -> f KafkaAction
kafkaAction_destinationArn = (KafkaAction -> Text)
-> (KafkaAction -> Text -> KafkaAction)
-> Lens KafkaAction KafkaAction Text Text
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 :: (Text -> f Text) -> KafkaAction -> f KafkaAction
kafkaAction_topic = (KafkaAction -> Text)
-> (KafkaAction -> Text -> KafkaAction)
-> Lens KafkaAction KafkaAction Text Text
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 :: (HashMap Text Text -> f (HashMap Text Text))
-> KafkaAction -> f KafkaAction
kafkaAction_clientProperties = (KafkaAction -> HashMap Text Text)
-> (KafkaAction -> HashMap Text Text -> KafkaAction)
-> Lens
     KafkaAction KafkaAction (HashMap Text Text) (HashMap Text Text)
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) ((HashMap Text Text -> f (HashMap Text Text))
 -> KafkaAction -> f KafkaAction)
-> ((HashMap Text Text -> f (HashMap Text Text))
    -> HashMap Text Text -> f (HashMap Text Text))
-> (HashMap Text Text -> f (HashMap Text Text))
-> KafkaAction
-> f KafkaAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text Text -> f (HashMap Text Text))
-> HashMap Text Text -> f (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable KafkaAction

instance Prelude.NFData KafkaAction

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"key" 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
key,
            (Text
"partition" 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
partition,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"destinationArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
destinationArn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"topic" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
topic),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"clientProperties" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text Text
clientProperties)
          ]
      )