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

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

-- | Describes an action to republish to another topic.
--
-- /See:/ 'newRepublishAction' smart constructor.
data RepublishAction = RepublishAction'
  { -- | The Quality of Service (QoS) level to use when republishing messages.
    -- The default value is 0.
    RepublishAction -> Maybe Natural
qos :: Prelude.Maybe Prelude.Natural,
    -- | The ARN of the IAM role that grants access.
    RepublishAction -> Text
roleArn :: Prelude.Text,
    -- | The name of the MQTT topic.
    RepublishAction -> Text
topic :: Prelude.Text
  }
  deriving (RepublishAction -> RepublishAction -> Bool
(RepublishAction -> RepublishAction -> Bool)
-> (RepublishAction -> RepublishAction -> Bool)
-> Eq RepublishAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RepublishAction -> RepublishAction -> Bool
$c/= :: RepublishAction -> RepublishAction -> Bool
== :: RepublishAction -> RepublishAction -> Bool
$c== :: RepublishAction -> RepublishAction -> Bool
Prelude.Eq, ReadPrec [RepublishAction]
ReadPrec RepublishAction
Int -> ReadS RepublishAction
ReadS [RepublishAction]
(Int -> ReadS RepublishAction)
-> ReadS [RepublishAction]
-> ReadPrec RepublishAction
-> ReadPrec [RepublishAction]
-> Read RepublishAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RepublishAction]
$creadListPrec :: ReadPrec [RepublishAction]
readPrec :: ReadPrec RepublishAction
$creadPrec :: ReadPrec RepublishAction
readList :: ReadS [RepublishAction]
$creadList :: ReadS [RepublishAction]
readsPrec :: Int -> ReadS RepublishAction
$creadsPrec :: Int -> ReadS RepublishAction
Prelude.Read, Int -> RepublishAction -> ShowS
[RepublishAction] -> ShowS
RepublishAction -> String
(Int -> RepublishAction -> ShowS)
-> (RepublishAction -> String)
-> ([RepublishAction] -> ShowS)
-> Show RepublishAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RepublishAction] -> ShowS
$cshowList :: [RepublishAction] -> ShowS
show :: RepublishAction -> String
$cshow :: RepublishAction -> String
showsPrec :: Int -> RepublishAction -> ShowS
$cshowsPrec :: Int -> RepublishAction -> ShowS
Prelude.Show, (forall x. RepublishAction -> Rep RepublishAction x)
-> (forall x. Rep RepublishAction x -> RepublishAction)
-> Generic RepublishAction
forall x. Rep RepublishAction x -> RepublishAction
forall x. RepublishAction -> Rep RepublishAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RepublishAction x -> RepublishAction
$cfrom :: forall x. RepublishAction -> Rep RepublishAction x
Prelude.Generic)

-- |
-- Create a value of 'RepublishAction' 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:
--
-- 'qos', 'republishAction_qos' - The Quality of Service (QoS) level to use when republishing messages.
-- The default value is 0.
--
-- 'roleArn', 'republishAction_roleArn' - The ARN of the IAM role that grants access.
--
-- 'topic', 'republishAction_topic' - The name of the MQTT topic.
newRepublishAction ::
  -- | 'roleArn'
  Prelude.Text ->
  -- | 'topic'
  Prelude.Text ->
  RepublishAction
newRepublishAction :: Text -> Text -> RepublishAction
newRepublishAction Text
pRoleArn_ Text
pTopic_ =
  RepublishAction' :: Maybe Natural -> Text -> Text -> RepublishAction
RepublishAction'
    { $sel:qos:RepublishAction' :: Maybe Natural
qos = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:RepublishAction' :: Text
roleArn = Text
pRoleArn_,
      $sel:topic:RepublishAction' :: Text
topic = Text
pTopic_
    }

-- | The Quality of Service (QoS) level to use when republishing messages.
-- The default value is 0.
republishAction_qos :: Lens.Lens' RepublishAction (Prelude.Maybe Prelude.Natural)
republishAction_qos :: (Maybe Natural -> f (Maybe Natural))
-> RepublishAction -> f RepublishAction
republishAction_qos = (RepublishAction -> Maybe Natural)
-> (RepublishAction -> Maybe Natural -> RepublishAction)
-> Lens
     RepublishAction RepublishAction (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RepublishAction' {Maybe Natural
qos :: Maybe Natural
$sel:qos:RepublishAction' :: RepublishAction -> Maybe Natural
qos} -> Maybe Natural
qos) (\s :: RepublishAction
s@RepublishAction' {} Maybe Natural
a -> RepublishAction
s {$sel:qos:RepublishAction' :: Maybe Natural
qos = Maybe Natural
a} :: RepublishAction)

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

-- | The name of the MQTT topic.
republishAction_topic :: Lens.Lens' RepublishAction Prelude.Text
republishAction_topic :: (Text -> f Text) -> RepublishAction -> f RepublishAction
republishAction_topic = (RepublishAction -> Text)
-> (RepublishAction -> Text -> RepublishAction)
-> Lens RepublishAction RepublishAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RepublishAction' {Text
topic :: Text
$sel:topic:RepublishAction' :: RepublishAction -> Text
topic} -> Text
topic) (\s :: RepublishAction
s@RepublishAction' {} Text
a -> RepublishAction
s {$sel:topic:RepublishAction' :: Text
topic = Text
a} :: RepublishAction)

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

instance Prelude.Hashable RepublishAction

instance Prelude.NFData RepublishAction

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