{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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 qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoT.Types
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
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]
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
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.
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'
      { $sel:destinationConfiguration:CreateTopicRuleDestination' :: TopicRuleDestinationConfiguration
destinationConfiguration =
          TopicRuleDestinationConfiguration
pDestinationConfiguration_
      }

-- | The topic rule destination configuration.
createTopicRuleDestination_destinationConfiguration :: Lens.Lens' CreateTopicRuleDestination TopicRuleDestinationConfiguration
createTopicRuleDestination_destinationConfiguration :: Lens' CreateTopicRuleDestination TopicRuleDestinationConfiguration
createTopicRuleDestination_destinationConfiguration = 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 :: (Service -> Service)
-> CreateTopicRuleDestination -> Request CreateTopicRuleDestination
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy CreateTopicRuleDestination
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateTopicRuleDestination)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe TopicRuleDestination
-> Int -> CreateTopicRuleDestinationResponse
CreateTopicRuleDestinationResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"topicRuleDestination")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CreateTopicRuleDestination where
  hashWithSalt :: Int -> CreateTopicRuleDestination -> Int
hashWithSalt Int
_salt CreateTopicRuleDestination' {TopicRuleDestinationConfiguration
destinationConfiguration :: TopicRuleDestinationConfiguration
$sel:destinationConfiguration:CreateTopicRuleDestination' :: CreateTopicRuleDestination -> TopicRuleDestinationConfiguration
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` TopicRuleDestinationConfiguration
destinationConfiguration

instance Prelude.NFData CreateTopicRuleDestination where
  rnf :: CreateTopicRuleDestination -> ()
rnf CreateTopicRuleDestination' {TopicRuleDestinationConfiguration
destinationConfiguration :: TopicRuleDestinationConfiguration
$sel:destinationConfiguration:CreateTopicRuleDestination' :: CreateTopicRuleDestination -> TopicRuleDestinationConfiguration
..} =
    forall a. NFData a => a -> ()
Prelude.rnf TopicRuleDestinationConfiguration
destinationConfiguration

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

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

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

instance Data.ToQuery CreateTopicRuleDestination where
  toQuery :: CreateTopicRuleDestination -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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.
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'
    { $sel:topicRuleDestination:CreateTopicRuleDestinationResponse' :: Maybe TopicRuleDestination
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 :: Lens'
  CreateTopicRuleDestinationResponse (Maybe TopicRuleDestination)
createTopicRuleDestinationResponse_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 :: Lens' CreateTopicRuleDestinationResponse Int
createTopicRuleDestinationResponse_httpStatus = 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
  where
  rnf :: CreateTopicRuleDestinationResponse -> ()
rnf CreateTopicRuleDestinationResponse' {Int
Maybe TopicRuleDestination
httpStatus :: Int
topicRuleDestination :: Maybe TopicRuleDestination
$sel:httpStatus:CreateTopicRuleDestinationResponse' :: CreateTopicRuleDestinationResponse -> Int
$sel:topicRuleDestination:CreateTopicRuleDestinationResponse' :: CreateTopicRuleDestinationResponse -> Maybe TopicRuleDestination
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe TopicRuleDestination
topicRuleDestination
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus