{-# 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.IoTSiteWise.Types.Measurement
-- 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.IoTSiteWise.Types.Measurement where

import qualified Amazonka.Core as Core
import Amazonka.IoTSiteWise.Types.MeasurementProcessingConfig
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains an asset measurement property. For more information, see
-- <https://docs.aws.amazon.com/iot-sitewise/latest/userguide/asset-properties.html#measurements Measurements>
-- in the /IoT SiteWise User Guide/.
--
-- /See:/ 'newMeasurement' smart constructor.
data Measurement = Measurement'
  { -- | The processing configuration for the given measurement property. You can
    -- configure measurements to be kept at the edge or forwarded to the Amazon
    -- Web Services Cloud. By default, measurements are forwarded to the cloud.
    Measurement -> Maybe MeasurementProcessingConfig
processingConfig :: Prelude.Maybe MeasurementProcessingConfig
  }
  deriving (Measurement -> Measurement -> Bool
(Measurement -> Measurement -> Bool)
-> (Measurement -> Measurement -> Bool) -> Eq Measurement
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Measurement -> Measurement -> Bool
$c/= :: Measurement -> Measurement -> Bool
== :: Measurement -> Measurement -> Bool
$c== :: Measurement -> Measurement -> Bool
Prelude.Eq, ReadPrec [Measurement]
ReadPrec Measurement
Int -> ReadS Measurement
ReadS [Measurement]
(Int -> ReadS Measurement)
-> ReadS [Measurement]
-> ReadPrec Measurement
-> ReadPrec [Measurement]
-> Read Measurement
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Measurement]
$creadListPrec :: ReadPrec [Measurement]
readPrec :: ReadPrec Measurement
$creadPrec :: ReadPrec Measurement
readList :: ReadS [Measurement]
$creadList :: ReadS [Measurement]
readsPrec :: Int -> ReadS Measurement
$creadsPrec :: Int -> ReadS Measurement
Prelude.Read, Int -> Measurement -> ShowS
[Measurement] -> ShowS
Measurement -> String
(Int -> Measurement -> ShowS)
-> (Measurement -> String)
-> ([Measurement] -> ShowS)
-> Show Measurement
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Measurement] -> ShowS
$cshowList :: [Measurement] -> ShowS
show :: Measurement -> String
$cshow :: Measurement -> String
showsPrec :: Int -> Measurement -> ShowS
$cshowsPrec :: Int -> Measurement -> ShowS
Prelude.Show, (forall x. Measurement -> Rep Measurement x)
-> (forall x. Rep Measurement x -> Measurement)
-> Generic Measurement
forall x. Rep Measurement x -> Measurement
forall x. Measurement -> Rep Measurement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Measurement x -> Measurement
$cfrom :: forall x. Measurement -> Rep Measurement x
Prelude.Generic)

-- |
-- Create a value of 'Measurement' 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:
--
-- 'processingConfig', 'measurement_processingConfig' - The processing configuration for the given measurement property. You can
-- configure measurements to be kept at the edge or forwarded to the Amazon
-- Web Services Cloud. By default, measurements are forwarded to the cloud.
newMeasurement ::
  Measurement
newMeasurement :: Measurement
newMeasurement =
  Measurement' :: Maybe MeasurementProcessingConfig -> Measurement
Measurement' {$sel:processingConfig:Measurement' :: Maybe MeasurementProcessingConfig
processingConfig = Maybe MeasurementProcessingConfig
forall a. Maybe a
Prelude.Nothing}

-- | The processing configuration for the given measurement property. You can
-- configure measurements to be kept at the edge or forwarded to the Amazon
-- Web Services Cloud. By default, measurements are forwarded to the cloud.
measurement_processingConfig :: Lens.Lens' Measurement (Prelude.Maybe MeasurementProcessingConfig)
measurement_processingConfig :: (Maybe MeasurementProcessingConfig
 -> f (Maybe MeasurementProcessingConfig))
-> Measurement -> f Measurement
measurement_processingConfig = (Measurement -> Maybe MeasurementProcessingConfig)
-> (Measurement
    -> Maybe MeasurementProcessingConfig -> Measurement)
-> Lens
     Measurement
     Measurement
     (Maybe MeasurementProcessingConfig)
     (Maybe MeasurementProcessingConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Measurement' {Maybe MeasurementProcessingConfig
processingConfig :: Maybe MeasurementProcessingConfig
$sel:processingConfig:Measurement' :: Measurement -> Maybe MeasurementProcessingConfig
processingConfig} -> Maybe MeasurementProcessingConfig
processingConfig) (\s :: Measurement
s@Measurement' {} Maybe MeasurementProcessingConfig
a -> Measurement
s {$sel:processingConfig:Measurement' :: Maybe MeasurementProcessingConfig
processingConfig = Maybe MeasurementProcessingConfig
a} :: Measurement)

instance Core.FromJSON Measurement where
  parseJSON :: Value -> Parser Measurement
parseJSON =
    String
-> (Object -> Parser Measurement) -> Value -> Parser Measurement
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Measurement"
      ( \Object
x ->
          Maybe MeasurementProcessingConfig -> Measurement
Measurement'
            (Maybe MeasurementProcessingConfig -> Measurement)
-> Parser (Maybe MeasurementProcessingConfig) -> Parser Measurement
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe MeasurementProcessingConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"processingConfig")
      )

instance Prelude.Hashable Measurement

instance Prelude.NFData Measurement

instance Core.ToJSON Measurement where
  toJSON :: Measurement -> Value
toJSON Measurement' {Maybe MeasurementProcessingConfig
processingConfig :: Maybe MeasurementProcessingConfig
$sel:processingConfig:Measurement' :: Measurement -> Maybe MeasurementProcessingConfig
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"processingConfig" Text -> MeasurementProcessingConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (MeasurementProcessingConfig -> Pair)
-> Maybe MeasurementProcessingConfig -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe MeasurementProcessingConfig
processingConfig
          ]
      )