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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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 @password@ key in an MQTT authorization request.
    MqttContext -> Maybe Base64
password :: Prelude.Maybe Data.Base64,
    -- | The value of the @username@ key in an MQTT authorization request.
    MqttContext -> Maybe Text
username :: Prelude.Maybe Prelude.Text
  }
  deriving (MqttContext -> MqttContext -> Bool
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]
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
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. 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.
--
-- '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.
--
-- 'username', 'mqttContext_username' - The value of the @username@ key in an MQTT authorization request.
newMqttContext ::
  MqttContext
newMqttContext :: MqttContext
newMqttContext =
  MqttContext'
    { $sel:clientId:MqttContext' :: Maybe Text
clientId = forall a. Maybe a
Prelude.Nothing,
      $sel:password:MqttContext' :: Maybe Base64
password = forall a. Maybe a
Prelude.Nothing,
      $sel:username:MqttContext' :: Maybe Text
username = 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 :: Lens' MqttContext (Maybe Text)
mqttContext_clientId = 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 @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 :: Lens' MqttContext (Maybe ByteString)
mqttContext_password = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 Iso' Base64 ByteString
Data._Base64

-- | The value of the @username@ key in an MQTT authorization request.
mqttContext_username :: Lens.Lens' MqttContext (Prelude.Maybe Prelude.Text)
mqttContext_username :: Lens' MqttContext (Maybe Text)
mqttContext_username = 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)

instance Prelude.Hashable MqttContext where
  hashWithSalt :: Int -> MqttContext -> Int
hashWithSalt Int
_salt MqttContext' {Maybe Text
Maybe Base64
username :: Maybe Text
password :: Maybe Base64
clientId :: Maybe Text
$sel:username:MqttContext' :: MqttContext -> Maybe Text
$sel:password:MqttContext' :: MqttContext -> Maybe Base64
$sel:clientId:MqttContext' :: MqttContext -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
clientId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Base64
password
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
username

instance Prelude.NFData MqttContext where
  rnf :: MqttContext -> ()
rnf MqttContext' {Maybe Text
Maybe Base64
username :: Maybe Text
password :: Maybe Base64
clientId :: Maybe Text
$sel:username:MqttContext' :: MqttContext -> Maybe Text
$sel:password:MqttContext' :: MqttContext -> Maybe Base64
$sel:clientId:MqttContext' :: MqttContext -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
clientId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Base64
password
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
username

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