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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoT.Types.MqttHeaders
import qualified Amazonka.Prelude as Prelude

-- | Describes an action to republish to another topic.
--
-- /See:/ 'newRepublishAction' smart constructor.
data RepublishAction = RepublishAction'
  { -- | MQTT Version 5.0 headers information. For more information, see
    -- <https://docs.aws.amazon.com/iot/latest/developerguide/mqtt.html MQTT>
    -- from the Amazon Web Services IoT Core Developer Guide.
    RepublishAction -> Maybe MqttHeaders
headers :: Prelude.Maybe MqttHeaders,
    -- | 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
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]
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
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. 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:
--
-- 'headers', 'republishAction_headers' - MQTT Version 5.0 headers information. For more information, see
-- <https://docs.aws.amazon.com/iot/latest/developerguide/mqtt.html MQTT>
-- from the Amazon Web Services IoT Core Developer Guide.
--
-- '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'
    { $sel:headers:RepublishAction' :: Maybe MqttHeaders
headers = forall a. Maybe a
Prelude.Nothing,
      $sel:qos:RepublishAction' :: Maybe Natural
qos = forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:RepublishAction' :: Text
roleArn = Text
pRoleArn_,
      $sel:topic:RepublishAction' :: Text
topic = Text
pTopic_
    }

-- | MQTT Version 5.0 headers information. For more information, see
-- <https://docs.aws.amazon.com/iot/latest/developerguide/mqtt.html MQTT>
-- from the Amazon Web Services IoT Core Developer Guide.
republishAction_headers :: Lens.Lens' RepublishAction (Prelude.Maybe MqttHeaders)
republishAction_headers :: Lens' RepublishAction (Maybe MqttHeaders)
republishAction_headers = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RepublishAction' {Maybe MqttHeaders
headers :: Maybe MqttHeaders
$sel:headers:RepublishAction' :: RepublishAction -> Maybe MqttHeaders
headers} -> Maybe MqttHeaders
headers) (\s :: RepublishAction
s@RepublishAction' {} Maybe MqttHeaders
a -> RepublishAction
s {$sel:headers:RepublishAction' :: Maybe MqttHeaders
headers = Maybe MqttHeaders
a} :: RepublishAction)

-- | 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 :: Lens' RepublishAction (Maybe Natural)
republishAction_qos = 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 :: Lens' RepublishAction Text
republishAction_roleArn = 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 :: Lens' RepublishAction Text
republishAction_topic = 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 Data.FromJSON RepublishAction where
  parseJSON :: Value -> Parser RepublishAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RepublishAction"
      ( \Object
x ->
          Maybe MqttHeaders
-> Maybe Natural -> Text -> Text -> RepublishAction
RepublishAction'
            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
"headers")
            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
"qos")
            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
"topic")
      )

instance Prelude.Hashable RepublishAction where
  hashWithSalt :: Int -> RepublishAction -> Int
hashWithSalt Int
_salt RepublishAction' {Maybe Natural
Maybe MqttHeaders
Text
topic :: Text
roleArn :: Text
qos :: Maybe Natural
headers :: Maybe MqttHeaders
$sel:topic:RepublishAction' :: RepublishAction -> Text
$sel:roleArn:RepublishAction' :: RepublishAction -> Text
$sel:qos:RepublishAction' :: RepublishAction -> Maybe Natural
$sel:headers:RepublishAction' :: RepublishAction -> Maybe MqttHeaders
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe MqttHeaders
headers
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
qos
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
roleArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
topic

instance Prelude.NFData RepublishAction where
  rnf :: RepublishAction -> ()
rnf RepublishAction' {Maybe Natural
Maybe MqttHeaders
Text
topic :: Text
roleArn :: Text
qos :: Maybe Natural
headers :: Maybe MqttHeaders
$sel:topic:RepublishAction' :: RepublishAction -> Text
$sel:roleArn:RepublishAction' :: RepublishAction -> Text
$sel:qos:RepublishAction' :: RepublishAction -> Maybe Natural
$sel:headers:RepublishAction' :: RepublishAction -> Maybe MqttHeaders
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe MqttHeaders
headers
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
qos
      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
topic

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