{-# 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.UserProperty
-- 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.UserProperty 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

-- | A key-value pair that you define in the header. Both the key and the
-- value are either literal strings or valid
-- <https://docs.aws.amazon.com/iot/latest/developerguide/iot-substitution-templates.html substitution templates>.
--
-- /See:/ 'newUserProperty' smart constructor.
data UserProperty = UserProperty'
  { -- | A key to be specified in @UserProperty@.
    UserProperty -> Text
key :: Prelude.Text,
    -- | A value to be specified in @UserProperty@.
    UserProperty -> Text
value :: Prelude.Text
  }
  deriving (UserProperty -> UserProperty -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UserProperty -> UserProperty -> Bool
$c/= :: UserProperty -> UserProperty -> Bool
== :: UserProperty -> UserProperty -> Bool
$c== :: UserProperty -> UserProperty -> Bool
Prelude.Eq, ReadPrec [UserProperty]
ReadPrec UserProperty
Int -> ReadS UserProperty
ReadS [UserProperty]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UserProperty]
$creadListPrec :: ReadPrec [UserProperty]
readPrec :: ReadPrec UserProperty
$creadPrec :: ReadPrec UserProperty
readList :: ReadS [UserProperty]
$creadList :: ReadS [UserProperty]
readsPrec :: Int -> ReadS UserProperty
$creadsPrec :: Int -> ReadS UserProperty
Prelude.Read, Int -> UserProperty -> ShowS
[UserProperty] -> ShowS
UserProperty -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UserProperty] -> ShowS
$cshowList :: [UserProperty] -> ShowS
show :: UserProperty -> String
$cshow :: UserProperty -> String
showsPrec :: Int -> UserProperty -> ShowS
$cshowsPrec :: Int -> UserProperty -> ShowS
Prelude.Show, forall x. Rep UserProperty x -> UserProperty
forall x. UserProperty -> Rep UserProperty x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UserProperty x -> UserProperty
$cfrom :: forall x. UserProperty -> Rep UserProperty x
Prelude.Generic)

-- |
-- Create a value of 'UserProperty' 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:
--
-- 'key', 'userProperty_key' - A key to be specified in @UserProperty@.
--
-- 'value', 'userProperty_value' - A value to be specified in @UserProperty@.
newUserProperty ::
  -- | 'key'
  Prelude.Text ->
  -- | 'value'
  Prelude.Text ->
  UserProperty
newUserProperty :: Text -> Text -> UserProperty
newUserProperty Text
pKey_ Text
pValue_ =
  UserProperty' {$sel:key:UserProperty' :: Text
key = Text
pKey_, $sel:value:UserProperty' :: Text
value = Text
pValue_}

-- | A key to be specified in @UserProperty@.
userProperty_key :: Lens.Lens' UserProperty Prelude.Text
userProperty_key :: Lens' UserProperty Text
userProperty_key = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UserProperty' {Text
key :: Text
$sel:key:UserProperty' :: UserProperty -> Text
key} -> Text
key) (\s :: UserProperty
s@UserProperty' {} Text
a -> UserProperty
s {$sel:key:UserProperty' :: Text
key = Text
a} :: UserProperty)

-- | A value to be specified in @UserProperty@.
userProperty_value :: Lens.Lens' UserProperty Prelude.Text
userProperty_value :: Lens' UserProperty Text
userProperty_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UserProperty' {Text
value :: Text
$sel:value:UserProperty' :: UserProperty -> Text
value} -> Text
value) (\s :: UserProperty
s@UserProperty' {} Text
a -> UserProperty
s {$sel:value:UserProperty' :: Text
value = Text
a} :: UserProperty)

instance Data.FromJSON UserProperty where
  parseJSON :: Value -> Parser UserProperty
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"UserProperty"
      ( \Object
x ->
          Text -> Text -> UserProperty
UserProperty'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"key")
            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
"value")
      )

instance Prelude.Hashable UserProperty where
  hashWithSalt :: Int -> UserProperty -> Int
hashWithSalt Int
_salt UserProperty' {Text
value :: Text
key :: Text
$sel:value:UserProperty' :: UserProperty -> Text
$sel:key:UserProperty' :: UserProperty -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
key
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
value

instance Prelude.NFData UserProperty where
  rnf :: UserProperty -> ()
rnf UserProperty' {Text
value :: Text
key :: Text
$sel:value:UserProperty' :: UserProperty -> Text
$sel:key:UserProperty' :: UserProperty -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
key seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
value

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