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

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

-- | Specifies the MQTT context to use for the test authorizer request
--
-- /See:/ 'newMqttContext' smart constructor.
data MqttContext = MqttContext'
  { -- | The value of the @clientId@ key in an MQTT authorization request.
    MqttContext -> Maybe Text
clientId :: Prelude.Maybe Prelude.Text,
    -- | The value of the @username@ key in an MQTT authorization request.
    MqttContext -> Maybe Text
username :: Prelude.Maybe Prelude.Text,
    -- | The value of the @password@ key in an MQTT authorization request.
    MqttContext -> Maybe Base64
password :: Prelude.Maybe Core.Base64
  }
  deriving (MqttContext -> MqttContext -> Bool
(MqttContext -> MqttContext -> Bool)
-> (MqttContext -> MqttContext -> Bool) -> Eq MqttContext
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MqttContext -> MqttContext -> Bool
$c/= :: MqttContext -> MqttContext -> Bool
== :: MqttContext -> MqttContext -> Bool
$c== :: MqttContext -> MqttContext -> Bool
Prelude.Eq, ReadPrec [MqttContext]
ReadPrec MqttContext
Int -> ReadS MqttContext
ReadS [MqttContext]
(Int -> ReadS MqttContext)
-> ReadS [MqttContext]
-> ReadPrec MqttContext
-> ReadPrec [MqttContext]
-> Read MqttContext
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MqttContext]
$creadListPrec :: ReadPrec [MqttContext]
readPrec :: ReadPrec MqttContext
$creadPrec :: ReadPrec MqttContext
readList :: ReadS [MqttContext]
$creadList :: ReadS [MqttContext]
readsPrec :: Int -> ReadS MqttContext
$creadsPrec :: Int -> ReadS MqttContext
Prelude.Read, Int -> MqttContext -> ShowS
[MqttContext] -> ShowS
MqttContext -> String
(Int -> MqttContext -> ShowS)
-> (MqttContext -> String)
-> ([MqttContext] -> ShowS)
-> Show MqttContext
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MqttContext] -> ShowS
$cshowList :: [MqttContext] -> ShowS
show :: MqttContext -> String
$cshow :: MqttContext -> String
showsPrec :: Int -> MqttContext -> ShowS
$cshowsPrec :: Int -> MqttContext -> ShowS
Prelude.Show, (forall x. MqttContext -> Rep MqttContext x)
-> (forall x. Rep MqttContext x -> MqttContext)
-> Generic MqttContext
forall x. Rep MqttContext x -> MqttContext
forall x. MqttContext -> Rep MqttContext x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MqttContext x -> MqttContext
$cfrom :: forall x. MqttContext -> Rep MqttContext x
Prelude.Generic)

-- |
-- Create a value of 'MqttContext' 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:
--
-- 'clientId', 'mqttContext_clientId' - The value of the @clientId@ key in an MQTT authorization request.
--
-- 'username', 'mqttContext_username' - The value of the @username@ key in an MQTT authorization request.
--
-- 'password', 'mqttContext_password' - The value of the @password@ key in an MQTT authorization request.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
newMqttContext ::
  MqttContext
newMqttContext :: MqttContext
newMqttContext =
  MqttContext' :: Maybe Text -> Maybe Text -> Maybe Base64 -> MqttContext
MqttContext'
    { $sel:clientId:MqttContext' :: Maybe Text
clientId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:username:MqttContext' :: Maybe Text
username = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:password:MqttContext' :: Maybe Base64
password = Maybe Base64
forall a. Maybe a
Prelude.Nothing
    }

-- | The value of the @clientId@ key in an MQTT authorization request.
mqttContext_clientId :: Lens.Lens' MqttContext (Prelude.Maybe Prelude.Text)
mqttContext_clientId :: (Maybe Text -> f (Maybe Text)) -> MqttContext -> f MqttContext
mqttContext_clientId = (MqttContext -> Maybe Text)
-> (MqttContext -> Maybe Text -> MqttContext)
-> Lens MqttContext MqttContext (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MqttContext' {Maybe Text
clientId :: Maybe Text
$sel:clientId:MqttContext' :: MqttContext -> Maybe Text
clientId} -> Maybe Text
clientId) (\s :: MqttContext
s@MqttContext' {} Maybe Text
a -> MqttContext
s {$sel:clientId:MqttContext' :: Maybe Text
clientId = Maybe Text
a} :: MqttContext)

-- | The value of the @username@ key in an MQTT authorization request.
mqttContext_username :: Lens.Lens' MqttContext (Prelude.Maybe Prelude.Text)
mqttContext_username :: (Maybe Text -> f (Maybe Text)) -> MqttContext -> f MqttContext
mqttContext_username = (MqttContext -> Maybe Text)
-> (MqttContext -> Maybe Text -> MqttContext)
-> Lens MqttContext MqttContext (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MqttContext' {Maybe Text
username :: Maybe Text
$sel:username:MqttContext' :: MqttContext -> Maybe Text
username} -> Maybe Text
username) (\s :: MqttContext
s@MqttContext' {} Maybe Text
a -> MqttContext
s {$sel:username:MqttContext' :: Maybe Text
username = Maybe Text
a} :: MqttContext)

-- | The value of the @password@ key in an MQTT authorization request.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
mqttContext_password :: Lens.Lens' MqttContext (Prelude.Maybe Prelude.ByteString)
mqttContext_password :: (Maybe ByteString -> f (Maybe ByteString))
-> MqttContext -> f MqttContext
mqttContext_password = (MqttContext -> Maybe Base64)
-> (MqttContext -> Maybe Base64 -> MqttContext)
-> Lens MqttContext MqttContext (Maybe Base64) (Maybe Base64)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MqttContext' {Maybe Base64
password :: Maybe Base64
$sel:password:MqttContext' :: MqttContext -> Maybe Base64
password} -> Maybe Base64
password) (\s :: MqttContext
s@MqttContext' {} Maybe Base64
a -> MqttContext
s {$sel:password:MqttContext' :: Maybe Base64
password = Maybe Base64
a} :: MqttContext) ((Maybe Base64 -> f (Maybe Base64))
 -> MqttContext -> f MqttContext)
-> ((Maybe ByteString -> f (Maybe ByteString))
    -> Maybe Base64 -> f (Maybe Base64))
-> (Maybe ByteString -> f (Maybe ByteString))
-> MqttContext
-> f MqttContext
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso Base64 Base64 ByteString ByteString
-> Iso
     (Maybe Base64) (Maybe Base64) (Maybe ByteString) (Maybe ByteString)
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso Base64 Base64 ByteString ByteString
Iso' Base64 ByteString
Core._Base64

instance Prelude.Hashable MqttContext

instance Prelude.NFData MqttContext

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