{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.CreateTopicRuleDestination
-- 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)
--
-- Creates a topic rule destination. The destination must be confirmed
-- prior to use.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions CreateTopicRuleDestination>
-- action.
module Amazonka.IoT.CreateTopicRuleDestination
  ( -- * Creating a Request
    CreateTopicRuleDestination (..),
    newCreateTopicRuleDestination,

    -- * Request Lenses
    createTopicRuleDestination_destinationConfiguration,

    -- * Destructuring the Response
    CreateTopicRuleDestinationResponse (..),
    newCreateTopicRuleDestinationResponse,

    -- * Response Lenses
    createTopicRuleDestinationResponse_topicRuleDestination,
    createTopicRuleDestinationResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCreateTopicRuleDestination' smart constructor.
data CreateTopicRuleDestination = CreateTopicRuleDestination'
  { -- | The topic rule destination configuration.
    CreateTopicRuleDestination -> TopicRuleDestinationConfiguration
destinationConfiguration :: TopicRuleDestinationConfiguration
  }
  deriving (CreateTopicRuleDestination -> CreateTopicRuleDestination -> Bool
(CreateTopicRuleDestination -> CreateTopicRuleDestination -> Bool)
-> (CreateTopicRuleDestination
    -> CreateTopicRuleDestination -> Bool)
-> Eq CreateTopicRuleDestination
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateTopicRuleDestination -> CreateTopicRuleDestination -> Bool
$c/= :: CreateTopicRuleDestination -> CreateTopicRuleDestination -> Bool
== :: CreateTopicRuleDestination -> CreateTopicRuleDestination -> Bool
$c== :: CreateTopicRuleDestination -> CreateTopicRuleDestination -> Bool
Prelude.Eq, ReadPrec [CreateTopicRuleDestination]
ReadPrec CreateTopicRuleDestination
Int -> ReadS CreateTopicRuleDestination
ReadS [CreateTopicRuleDestination]
(Int -> ReadS CreateTopicRuleDestination)
-> ReadS [CreateTopicRuleDestination]
-> ReadPrec CreateTopicRuleDestination
-> ReadPrec [CreateTopicRuleDestination]
-> Read CreateTopicRuleDestination
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateTopicRuleDestination]
$creadListPrec :: ReadPrec [CreateTopicRuleDestination]
readPrec :: ReadPrec CreateTopicRuleDestination
$creadPrec :: ReadPrec CreateTopicRuleDestination
readList :: ReadS [CreateTopicRuleDestination]
$creadList :: ReadS [CreateTopicRuleDestination]
readsPrec :: Int -> ReadS CreateTopicRuleDestination
$creadsPrec :: Int -> ReadS CreateTopicRuleDestination
Prelude.Read, Int -> CreateTopicRuleDestination -> ShowS
[CreateTopicRuleDestination] -> ShowS
CreateTopicRuleDestination -> String
(Int -> CreateTopicRuleDestination -> ShowS)
-> (CreateTopicRuleDestination -> String)
-> ([CreateTopicRuleDestination] -> ShowS)
-> Show CreateTopicRuleDestination
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateTopicRuleDestination] -> ShowS
$cshowList :: [CreateTopicRuleDestination] -> ShowS
show :: CreateTopicRuleDestination -> String
$cshow :: CreateTopicRuleDestination -> String
showsPrec :: Int -> CreateTopicRuleDestination -> ShowS
$cshowsPrec :: Int -> CreateTopicRuleDestination -> ShowS
Prelude.Show, (forall x.
 CreateTopicRuleDestination -> Rep CreateTopicRuleDestination x)
-> (forall x.
    Rep CreateTopicRuleDestination x -> CreateTopicRuleDestination)
-> Generic CreateTopicRuleDestination
forall x.
Rep CreateTopicRuleDestination x -> CreateTopicRuleDestination
forall x.
CreateTopicRuleDestination -> Rep CreateTopicRuleDestination x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateTopicRuleDestination x -> CreateTopicRuleDestination
$cfrom :: forall x.
CreateTopicRuleDestination -> Rep CreateTopicRuleDestination x
Prelude.Generic)

-- |
-- Create a value of 'CreateTopicRuleDestination' 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:
--
-- 'destinationConfiguration', 'createTopicRuleDestination_destinationConfiguration' - The topic rule destination configuration.
newCreateTopicRuleDestination ::
  -- | 'destinationConfiguration'
  TopicRuleDestinationConfiguration ->
  CreateTopicRuleDestination
newCreateTopicRuleDestination :: TopicRuleDestinationConfiguration -> CreateTopicRuleDestination
newCreateTopicRuleDestination
  TopicRuleDestinationConfiguration
pDestinationConfiguration_ =
    CreateTopicRuleDestination' :: TopicRuleDestinationConfiguration -> CreateTopicRuleDestination
CreateTopicRuleDestination'
      { $sel:destinationConfiguration:CreateTopicRuleDestination' :: TopicRuleDestinationConfiguration
destinationConfiguration =
          TopicRuleDestinationConfiguration
pDestinationConfiguration_
      }

-- | The topic rule destination configuration.
createTopicRuleDestination_destinationConfiguration :: Lens.Lens' CreateTopicRuleDestination TopicRuleDestinationConfiguration
createTopicRuleDestination_destinationConfiguration :: (TopicRuleDestinationConfiguration
 -> f TopicRuleDestinationConfiguration)
-> CreateTopicRuleDestination -> f CreateTopicRuleDestination
createTopicRuleDestination_destinationConfiguration = (CreateTopicRuleDestination -> TopicRuleDestinationConfiguration)
-> (CreateTopicRuleDestination
    -> TopicRuleDestinationConfiguration -> CreateTopicRuleDestination)
-> Lens
     CreateTopicRuleDestination
     CreateTopicRuleDestination
     TopicRuleDestinationConfiguration
     TopicRuleDestinationConfiguration
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateTopicRuleDestination' {TopicRuleDestinationConfiguration
destinationConfiguration :: TopicRuleDestinationConfiguration
$sel:destinationConfiguration:CreateTopicRuleDestination' :: CreateTopicRuleDestination -> TopicRuleDestinationConfiguration
destinationConfiguration} -> TopicRuleDestinationConfiguration
destinationConfiguration) (\s :: CreateTopicRuleDestination
s@CreateTopicRuleDestination' {} TopicRuleDestinationConfiguration
a -> CreateTopicRuleDestination
s {$sel:destinationConfiguration:CreateTopicRuleDestination' :: TopicRuleDestinationConfiguration
destinationConfiguration = TopicRuleDestinationConfiguration
a} :: CreateTopicRuleDestination)

instance Core.AWSRequest CreateTopicRuleDestination where
  type
    AWSResponse CreateTopicRuleDestination =
      CreateTopicRuleDestinationResponse
  request :: CreateTopicRuleDestination -> Request CreateTopicRuleDestination
request = Service
-> CreateTopicRuleDestination -> Request CreateTopicRuleDestination
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateTopicRuleDestination
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateTopicRuleDestination)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateTopicRuleDestination))
-> Logger
-> Service
-> Proxy CreateTopicRuleDestination
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateTopicRuleDestination)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe TopicRuleDestination
-> Int -> CreateTopicRuleDestinationResponse
CreateTopicRuleDestinationResponse'
            (Maybe TopicRuleDestination
 -> Int -> CreateTopicRuleDestinationResponse)
-> Either String (Maybe TopicRuleDestination)
-> Either String (Int -> CreateTopicRuleDestinationResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Key -> Either String (Maybe TopicRuleDestination)
forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Core..?> Key
"topicRuleDestination")
            Either String (Int -> CreateTopicRuleDestinationResponse)
-> Either String Int
-> Either String CreateTopicRuleDestinationResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CreateTopicRuleDestination

instance Prelude.NFData CreateTopicRuleDestination

instance Core.ToHeaders CreateTopicRuleDestination where
  toHeaders :: CreateTopicRuleDestination -> ResponseHeaders
toHeaders = ResponseHeaders -> CreateTopicRuleDestination -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToJSON CreateTopicRuleDestination where
  toJSON :: CreateTopicRuleDestination -> Value
toJSON CreateTopicRuleDestination' {TopicRuleDestinationConfiguration
destinationConfiguration :: TopicRuleDestinationConfiguration
$sel:destinationConfiguration:CreateTopicRuleDestination' :: CreateTopicRuleDestination -> TopicRuleDestinationConfiguration
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Key
"destinationConfiguration"
                  Key -> TopicRuleDestinationConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Core..= TopicRuleDestinationConfiguration
destinationConfiguration
              )
          ]
      )

instance Core.ToPath CreateTopicRuleDestination where
  toPath :: CreateTopicRuleDestination -> ByteString
toPath = ByteString -> CreateTopicRuleDestination -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/destinations"

instance Core.ToQuery CreateTopicRuleDestination where
  toQuery :: CreateTopicRuleDestination -> QueryString
toQuery = QueryString -> CreateTopicRuleDestination -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newCreateTopicRuleDestinationResponse' smart constructor.
data CreateTopicRuleDestinationResponse = CreateTopicRuleDestinationResponse'
  { -- | The topic rule destination.
    CreateTopicRuleDestinationResponse -> Maybe TopicRuleDestination
topicRuleDestination :: Prelude.Maybe TopicRuleDestination,
    -- | The response's http status code.
    CreateTopicRuleDestinationResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateTopicRuleDestinationResponse
-> CreateTopicRuleDestinationResponse -> Bool
(CreateTopicRuleDestinationResponse
 -> CreateTopicRuleDestinationResponse -> Bool)
-> (CreateTopicRuleDestinationResponse
    -> CreateTopicRuleDestinationResponse -> Bool)
-> Eq CreateTopicRuleDestinationResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateTopicRuleDestinationResponse
-> CreateTopicRuleDestinationResponse -> Bool
$c/= :: CreateTopicRuleDestinationResponse
-> CreateTopicRuleDestinationResponse -> Bool
== :: CreateTopicRuleDestinationResponse
-> CreateTopicRuleDestinationResponse -> Bool
$c== :: CreateTopicRuleDestinationResponse
-> CreateTopicRuleDestinationResponse -> Bool
Prelude.Eq, ReadPrec [CreateTopicRuleDestinationResponse]
ReadPrec CreateTopicRuleDestinationResponse
Int -> ReadS CreateTopicRuleDestinationResponse
ReadS [CreateTopicRuleDestinationResponse]
(Int -> ReadS CreateTopicRuleDestinationResponse)
-> ReadS [CreateTopicRuleDestinationResponse]
-> ReadPrec CreateTopicRuleDestinationResponse
-> ReadPrec [CreateTopicRuleDestinationResponse]
-> Read CreateTopicRuleDestinationResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateTopicRuleDestinationResponse]
$creadListPrec :: ReadPrec [CreateTopicRuleDestinationResponse]
readPrec :: ReadPrec CreateTopicRuleDestinationResponse
$creadPrec :: ReadPrec CreateTopicRuleDestinationResponse
readList :: ReadS [CreateTopicRuleDestinationResponse]
$creadList :: ReadS [CreateTopicRuleDestinationResponse]
readsPrec :: Int -> ReadS CreateTopicRuleDestinationResponse
$creadsPrec :: Int -> ReadS CreateTopicRuleDestinationResponse
Prelude.Read, Int -> CreateTopicRuleDestinationResponse -> ShowS
[CreateTopicRuleDestinationResponse] -> ShowS
CreateTopicRuleDestinationResponse -> String
(Int -> CreateTopicRuleDestinationResponse -> ShowS)
-> (CreateTopicRuleDestinationResponse -> String)
-> ([CreateTopicRuleDestinationResponse] -> ShowS)
-> Show CreateTopicRuleDestinationResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateTopicRuleDestinationResponse] -> ShowS
$cshowList :: [CreateTopicRuleDestinationResponse] -> ShowS
show :: CreateTopicRuleDestinationResponse -> String
$cshow :: CreateTopicRuleDestinationResponse -> String
showsPrec :: Int -> CreateTopicRuleDestinationResponse -> ShowS
$cshowsPrec :: Int -> CreateTopicRuleDestinationResponse -> ShowS
Prelude.Show, (forall x.
 CreateTopicRuleDestinationResponse
 -> Rep CreateTopicRuleDestinationResponse x)
-> (forall x.
    Rep CreateTopicRuleDestinationResponse x
    -> CreateTopicRuleDestinationResponse)
-> Generic CreateTopicRuleDestinationResponse
forall x.
Rep CreateTopicRuleDestinationResponse x
-> CreateTopicRuleDestinationResponse
forall x.
CreateTopicRuleDestinationResponse
-> Rep CreateTopicRuleDestinationResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateTopicRuleDestinationResponse x
-> CreateTopicRuleDestinationResponse
$cfrom :: forall x.
CreateTopicRuleDestinationResponse
-> Rep CreateTopicRuleDestinationResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateTopicRuleDestinationResponse' 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:
--
-- 'topicRuleDestination', 'createTopicRuleDestinationResponse_topicRuleDestination' - The topic rule destination.
--
-- 'httpStatus', 'createTopicRuleDestinationResponse_httpStatus' - The response's http status code.
newCreateTopicRuleDestinationResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateTopicRuleDestinationResponse
newCreateTopicRuleDestinationResponse :: Int -> CreateTopicRuleDestinationResponse
newCreateTopicRuleDestinationResponse Int
pHttpStatus_ =
  CreateTopicRuleDestinationResponse' :: Maybe TopicRuleDestination
-> Int -> CreateTopicRuleDestinationResponse
CreateTopicRuleDestinationResponse'
    { $sel:topicRuleDestination:CreateTopicRuleDestinationResponse' :: Maybe TopicRuleDestination
topicRuleDestination =
        Maybe TopicRuleDestination
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateTopicRuleDestinationResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The topic rule destination.
createTopicRuleDestinationResponse_topicRuleDestination :: Lens.Lens' CreateTopicRuleDestinationResponse (Prelude.Maybe TopicRuleDestination)
createTopicRuleDestinationResponse_topicRuleDestination :: (Maybe TopicRuleDestination -> f (Maybe TopicRuleDestination))
-> CreateTopicRuleDestinationResponse
-> f CreateTopicRuleDestinationResponse
createTopicRuleDestinationResponse_topicRuleDestination = (CreateTopicRuleDestinationResponse -> Maybe TopicRuleDestination)
-> (CreateTopicRuleDestinationResponse
    -> Maybe TopicRuleDestination
    -> CreateTopicRuleDestinationResponse)
-> Lens
     CreateTopicRuleDestinationResponse
     CreateTopicRuleDestinationResponse
     (Maybe TopicRuleDestination)
     (Maybe TopicRuleDestination)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateTopicRuleDestinationResponse' {Maybe TopicRuleDestination
topicRuleDestination :: Maybe TopicRuleDestination
$sel:topicRuleDestination:CreateTopicRuleDestinationResponse' :: CreateTopicRuleDestinationResponse -> Maybe TopicRuleDestination
topicRuleDestination} -> Maybe TopicRuleDestination
topicRuleDestination) (\s :: CreateTopicRuleDestinationResponse
s@CreateTopicRuleDestinationResponse' {} Maybe TopicRuleDestination
a -> CreateTopicRuleDestinationResponse
s {$sel:topicRuleDestination:CreateTopicRuleDestinationResponse' :: Maybe TopicRuleDestination
topicRuleDestination = Maybe TopicRuleDestination
a} :: CreateTopicRuleDestinationResponse)

-- | The response's http status code.
createTopicRuleDestinationResponse_httpStatus :: Lens.Lens' CreateTopicRuleDestinationResponse Prelude.Int
createTopicRuleDestinationResponse_httpStatus :: (Int -> f Int)
-> CreateTopicRuleDestinationResponse
-> f CreateTopicRuleDestinationResponse
createTopicRuleDestinationResponse_httpStatus = (CreateTopicRuleDestinationResponse -> Int)
-> (CreateTopicRuleDestinationResponse
    -> Int -> CreateTopicRuleDestinationResponse)
-> Lens
     CreateTopicRuleDestinationResponse
     CreateTopicRuleDestinationResponse
     Int
     Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateTopicRuleDestinationResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateTopicRuleDestinationResponse' :: CreateTopicRuleDestinationResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateTopicRuleDestinationResponse
s@CreateTopicRuleDestinationResponse' {} Int
a -> CreateTopicRuleDestinationResponse
s {$sel:httpStatus:CreateTopicRuleDestinationResponse' :: Int
httpStatus = Int
a} :: CreateTopicRuleDestinationResponse)

instance
  Prelude.NFData
    CreateTopicRuleDestinationResponse