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

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.AssetPropertyTimestamp
import Amazonka.IoT.Types.AssetPropertyVariant
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An asset property value entry containing the following information.
--
-- /See:/ 'newAssetPropertyValue' smart constructor.
data AssetPropertyValue = AssetPropertyValue'
  { -- | Optional. A string that describes the quality of the value. Accepts
    -- substitution templates. Must be @GOOD@, @BAD@, or @UNCERTAIN@.
    AssetPropertyValue -> Maybe Text
quality :: Prelude.Maybe Prelude.Text,
    -- | The value of the asset property.
    AssetPropertyValue -> AssetPropertyVariant
value :: AssetPropertyVariant,
    -- | The asset property value timestamp.
    AssetPropertyValue -> AssetPropertyTimestamp
timestamp :: AssetPropertyTimestamp
  }
  deriving (AssetPropertyValue -> AssetPropertyValue -> Bool
(AssetPropertyValue -> AssetPropertyValue -> Bool)
-> (AssetPropertyValue -> AssetPropertyValue -> Bool)
-> Eq AssetPropertyValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssetPropertyValue -> AssetPropertyValue -> Bool
$c/= :: AssetPropertyValue -> AssetPropertyValue -> Bool
== :: AssetPropertyValue -> AssetPropertyValue -> Bool
$c== :: AssetPropertyValue -> AssetPropertyValue -> Bool
Prelude.Eq, ReadPrec [AssetPropertyValue]
ReadPrec AssetPropertyValue
Int -> ReadS AssetPropertyValue
ReadS [AssetPropertyValue]
(Int -> ReadS AssetPropertyValue)
-> ReadS [AssetPropertyValue]
-> ReadPrec AssetPropertyValue
-> ReadPrec [AssetPropertyValue]
-> Read AssetPropertyValue
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssetPropertyValue]
$creadListPrec :: ReadPrec [AssetPropertyValue]
readPrec :: ReadPrec AssetPropertyValue
$creadPrec :: ReadPrec AssetPropertyValue
readList :: ReadS [AssetPropertyValue]
$creadList :: ReadS [AssetPropertyValue]
readsPrec :: Int -> ReadS AssetPropertyValue
$creadsPrec :: Int -> ReadS AssetPropertyValue
Prelude.Read, Int -> AssetPropertyValue -> ShowS
[AssetPropertyValue] -> ShowS
AssetPropertyValue -> String
(Int -> AssetPropertyValue -> ShowS)
-> (AssetPropertyValue -> String)
-> ([AssetPropertyValue] -> ShowS)
-> Show AssetPropertyValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssetPropertyValue] -> ShowS
$cshowList :: [AssetPropertyValue] -> ShowS
show :: AssetPropertyValue -> String
$cshow :: AssetPropertyValue -> String
showsPrec :: Int -> AssetPropertyValue -> ShowS
$cshowsPrec :: Int -> AssetPropertyValue -> ShowS
Prelude.Show, (forall x. AssetPropertyValue -> Rep AssetPropertyValue x)
-> (forall x. Rep AssetPropertyValue x -> AssetPropertyValue)
-> Generic AssetPropertyValue
forall x. Rep AssetPropertyValue x -> AssetPropertyValue
forall x. AssetPropertyValue -> Rep AssetPropertyValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssetPropertyValue x -> AssetPropertyValue
$cfrom :: forall x. AssetPropertyValue -> Rep AssetPropertyValue x
Prelude.Generic)

-- |
-- Create a value of 'AssetPropertyValue' 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:
--
-- 'quality', 'assetPropertyValue_quality' - Optional. A string that describes the quality of the value. Accepts
-- substitution templates. Must be @GOOD@, @BAD@, or @UNCERTAIN@.
--
-- 'value', 'assetPropertyValue_value' - The value of the asset property.
--
-- 'timestamp', 'assetPropertyValue_timestamp' - The asset property value timestamp.
newAssetPropertyValue ::
  -- | 'value'
  AssetPropertyVariant ->
  -- | 'timestamp'
  AssetPropertyTimestamp ->
  AssetPropertyValue
newAssetPropertyValue :: AssetPropertyVariant
-> AssetPropertyTimestamp -> AssetPropertyValue
newAssetPropertyValue AssetPropertyVariant
pValue_ AssetPropertyTimestamp
pTimestamp_ =
  AssetPropertyValue' :: Maybe Text
-> AssetPropertyVariant
-> AssetPropertyTimestamp
-> AssetPropertyValue
AssetPropertyValue'
    { $sel:quality:AssetPropertyValue' :: Maybe Text
quality = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:value:AssetPropertyValue' :: AssetPropertyVariant
value = AssetPropertyVariant
pValue_,
      $sel:timestamp:AssetPropertyValue' :: AssetPropertyTimestamp
timestamp = AssetPropertyTimestamp
pTimestamp_
    }

-- | Optional. A string that describes the quality of the value. Accepts
-- substitution templates. Must be @GOOD@, @BAD@, or @UNCERTAIN@.
assetPropertyValue_quality :: Lens.Lens' AssetPropertyValue (Prelude.Maybe Prelude.Text)
assetPropertyValue_quality :: (Maybe Text -> f (Maybe Text))
-> AssetPropertyValue -> f AssetPropertyValue
assetPropertyValue_quality = (AssetPropertyValue -> Maybe Text)
-> (AssetPropertyValue -> Maybe Text -> AssetPropertyValue)
-> Lens
     AssetPropertyValue AssetPropertyValue (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssetPropertyValue' {Maybe Text
quality :: Maybe Text
$sel:quality:AssetPropertyValue' :: AssetPropertyValue -> Maybe Text
quality} -> Maybe Text
quality) (\s :: AssetPropertyValue
s@AssetPropertyValue' {} Maybe Text
a -> AssetPropertyValue
s {$sel:quality:AssetPropertyValue' :: Maybe Text
quality = Maybe Text
a} :: AssetPropertyValue)

-- | The value of the asset property.
assetPropertyValue_value :: Lens.Lens' AssetPropertyValue AssetPropertyVariant
assetPropertyValue_value :: (AssetPropertyVariant -> f AssetPropertyVariant)
-> AssetPropertyValue -> f AssetPropertyValue
assetPropertyValue_value = (AssetPropertyValue -> AssetPropertyVariant)
-> (AssetPropertyValue
    -> AssetPropertyVariant -> AssetPropertyValue)
-> Lens
     AssetPropertyValue
     AssetPropertyValue
     AssetPropertyVariant
     AssetPropertyVariant
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssetPropertyValue' {AssetPropertyVariant
value :: AssetPropertyVariant
$sel:value:AssetPropertyValue' :: AssetPropertyValue -> AssetPropertyVariant
value} -> AssetPropertyVariant
value) (\s :: AssetPropertyValue
s@AssetPropertyValue' {} AssetPropertyVariant
a -> AssetPropertyValue
s {$sel:value:AssetPropertyValue' :: AssetPropertyVariant
value = AssetPropertyVariant
a} :: AssetPropertyValue)

-- | The asset property value timestamp.
assetPropertyValue_timestamp :: Lens.Lens' AssetPropertyValue AssetPropertyTimestamp
assetPropertyValue_timestamp :: (AssetPropertyTimestamp -> f AssetPropertyTimestamp)
-> AssetPropertyValue -> f AssetPropertyValue
assetPropertyValue_timestamp = (AssetPropertyValue -> AssetPropertyTimestamp)
-> (AssetPropertyValue
    -> AssetPropertyTimestamp -> AssetPropertyValue)
-> Lens
     AssetPropertyValue
     AssetPropertyValue
     AssetPropertyTimestamp
     AssetPropertyTimestamp
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssetPropertyValue' {AssetPropertyTimestamp
timestamp :: AssetPropertyTimestamp
$sel:timestamp:AssetPropertyValue' :: AssetPropertyValue -> AssetPropertyTimestamp
timestamp} -> AssetPropertyTimestamp
timestamp) (\s :: AssetPropertyValue
s@AssetPropertyValue' {} AssetPropertyTimestamp
a -> AssetPropertyValue
s {$sel:timestamp:AssetPropertyValue' :: AssetPropertyTimestamp
timestamp = AssetPropertyTimestamp
a} :: AssetPropertyValue)

instance Core.FromJSON AssetPropertyValue where
  parseJSON :: Value -> Parser AssetPropertyValue
parseJSON =
    String
-> (Object -> Parser AssetPropertyValue)
-> Value
-> Parser AssetPropertyValue
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AssetPropertyValue"
      ( \Object
x ->
          Maybe Text
-> AssetPropertyVariant
-> AssetPropertyTimestamp
-> AssetPropertyValue
AssetPropertyValue'
            (Maybe Text
 -> AssetPropertyVariant
 -> AssetPropertyTimestamp
 -> AssetPropertyValue)
-> Parser (Maybe Text)
-> Parser
     (AssetPropertyVariant
      -> AssetPropertyTimestamp -> AssetPropertyValue)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"quality")
            Parser
  (AssetPropertyVariant
   -> AssetPropertyTimestamp -> AssetPropertyValue)
-> Parser AssetPropertyVariant
-> Parser (AssetPropertyTimestamp -> AssetPropertyValue)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser AssetPropertyVariant
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"value")
            Parser (AssetPropertyTimestamp -> AssetPropertyValue)
-> Parser AssetPropertyTimestamp -> Parser AssetPropertyValue
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser AssetPropertyTimestamp
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"timestamp")
      )

instance Prelude.Hashable AssetPropertyValue

instance Prelude.NFData AssetPropertyValue

instance Core.ToJSON AssetPropertyValue where
  toJSON :: AssetPropertyValue -> Value
toJSON AssetPropertyValue' {Maybe Text
AssetPropertyTimestamp
AssetPropertyVariant
timestamp :: AssetPropertyTimestamp
value :: AssetPropertyVariant
quality :: Maybe Text
$sel:timestamp:AssetPropertyValue' :: AssetPropertyValue -> AssetPropertyTimestamp
$sel:value:AssetPropertyValue' :: AssetPropertyValue -> AssetPropertyVariant
$sel:quality:AssetPropertyValue' :: AssetPropertyValue -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"quality" 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
quality,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"value" Text -> AssetPropertyVariant -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= AssetPropertyVariant
value),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"timestamp" Text -> AssetPropertyTimestamp -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= AssetPropertyTimestamp
timestamp)
          ]
      )