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

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

-- | Contains an asset property value (of a single type only).
--
-- /See:/ 'newVariant' smart constructor.
data Variant = Variant'
  { -- | Asset property data of type integer (whole number).
    Variant -> Maybe Int
integerValue :: Prelude.Maybe Prelude.Int,
    -- | Asset property data of type double (floating point number).
    Variant -> Maybe Double
doubleValue :: Prelude.Maybe Prelude.Double,
    -- | Asset property data of type string (sequence of characters).
    Variant -> Maybe Text
stringValue :: Prelude.Maybe Prelude.Text,
    -- | Asset property data of type Boolean (true or false).
    Variant -> Maybe Bool
booleanValue :: Prelude.Maybe Prelude.Bool
  }
  deriving (Variant -> Variant -> Bool
(Variant -> Variant -> Bool)
-> (Variant -> Variant -> Bool) -> Eq Variant
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Variant -> Variant -> Bool
$c/= :: Variant -> Variant -> Bool
== :: Variant -> Variant -> Bool
$c== :: Variant -> Variant -> Bool
Prelude.Eq, ReadPrec [Variant]
ReadPrec Variant
Int -> ReadS Variant
ReadS [Variant]
(Int -> ReadS Variant)
-> ReadS [Variant]
-> ReadPrec Variant
-> ReadPrec [Variant]
-> Read Variant
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Variant]
$creadListPrec :: ReadPrec [Variant]
readPrec :: ReadPrec Variant
$creadPrec :: ReadPrec Variant
readList :: ReadS [Variant]
$creadList :: ReadS [Variant]
readsPrec :: Int -> ReadS Variant
$creadsPrec :: Int -> ReadS Variant
Prelude.Read, Int -> Variant -> ShowS
[Variant] -> ShowS
Variant -> String
(Int -> Variant -> ShowS)
-> (Variant -> String) -> ([Variant] -> ShowS) -> Show Variant
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Variant] -> ShowS
$cshowList :: [Variant] -> ShowS
show :: Variant -> String
$cshow :: Variant -> String
showsPrec :: Int -> Variant -> ShowS
$cshowsPrec :: Int -> Variant -> ShowS
Prelude.Show, (forall x. Variant -> Rep Variant x)
-> (forall x. Rep Variant x -> Variant) -> Generic Variant
forall x. Rep Variant x -> Variant
forall x. Variant -> Rep Variant x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Variant x -> Variant
$cfrom :: forall x. Variant -> Rep Variant x
Prelude.Generic)

-- |
-- Create a value of 'Variant' 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:
--
-- 'integerValue', 'variant_integerValue' - Asset property data of type integer (whole number).
--
-- 'doubleValue', 'variant_doubleValue' - Asset property data of type double (floating point number).
--
-- 'stringValue', 'variant_stringValue' - Asset property data of type string (sequence of characters).
--
-- 'booleanValue', 'variant_booleanValue' - Asset property data of type Boolean (true or false).
newVariant ::
  Variant
newVariant :: Variant
newVariant =
  Variant' :: Maybe Int -> Maybe Double -> Maybe Text -> Maybe Bool -> Variant
Variant'
    { $sel:integerValue:Variant' :: Maybe Int
integerValue = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:doubleValue:Variant' :: Maybe Double
doubleValue = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:stringValue:Variant' :: Maybe Text
stringValue = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:booleanValue:Variant' :: Maybe Bool
booleanValue = Maybe Bool
forall a. Maybe a
Prelude.Nothing
    }

-- | Asset property data of type integer (whole number).
variant_integerValue :: Lens.Lens' Variant (Prelude.Maybe Prelude.Int)
variant_integerValue :: (Maybe Int -> f (Maybe Int)) -> Variant -> f Variant
variant_integerValue = (Variant -> Maybe Int)
-> (Variant -> Maybe Int -> Variant)
-> Lens Variant Variant (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Variant' {Maybe Int
integerValue :: Maybe Int
$sel:integerValue:Variant' :: Variant -> Maybe Int
integerValue} -> Maybe Int
integerValue) (\s :: Variant
s@Variant' {} Maybe Int
a -> Variant
s {$sel:integerValue:Variant' :: Maybe Int
integerValue = Maybe Int
a} :: Variant)

-- | Asset property data of type double (floating point number).
variant_doubleValue :: Lens.Lens' Variant (Prelude.Maybe Prelude.Double)
variant_doubleValue :: (Maybe Double -> f (Maybe Double)) -> Variant -> f Variant
variant_doubleValue = (Variant -> Maybe Double)
-> (Variant -> Maybe Double -> Variant)
-> Lens Variant Variant (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Variant' {Maybe Double
doubleValue :: Maybe Double
$sel:doubleValue:Variant' :: Variant -> Maybe Double
doubleValue} -> Maybe Double
doubleValue) (\s :: Variant
s@Variant' {} Maybe Double
a -> Variant
s {$sel:doubleValue:Variant' :: Maybe Double
doubleValue = Maybe Double
a} :: Variant)

-- | Asset property data of type string (sequence of characters).
variant_stringValue :: Lens.Lens' Variant (Prelude.Maybe Prelude.Text)
variant_stringValue :: (Maybe Text -> f (Maybe Text)) -> Variant -> f Variant
variant_stringValue = (Variant -> Maybe Text)
-> (Variant -> Maybe Text -> Variant)
-> Lens Variant Variant (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Variant' {Maybe Text
stringValue :: Maybe Text
$sel:stringValue:Variant' :: Variant -> Maybe Text
stringValue} -> Maybe Text
stringValue) (\s :: Variant
s@Variant' {} Maybe Text
a -> Variant
s {$sel:stringValue:Variant' :: Maybe Text
stringValue = Maybe Text
a} :: Variant)

-- | Asset property data of type Boolean (true or false).
variant_booleanValue :: Lens.Lens' Variant (Prelude.Maybe Prelude.Bool)
variant_booleanValue :: (Maybe Bool -> f (Maybe Bool)) -> Variant -> f Variant
variant_booleanValue = (Variant -> Maybe Bool)
-> (Variant -> Maybe Bool -> Variant)
-> Lens Variant Variant (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Variant' {Maybe Bool
booleanValue :: Maybe Bool
$sel:booleanValue:Variant' :: Variant -> Maybe Bool
booleanValue} -> Maybe Bool
booleanValue) (\s :: Variant
s@Variant' {} Maybe Bool
a -> Variant
s {$sel:booleanValue:Variant' :: Maybe Bool
booleanValue = Maybe Bool
a} :: Variant)

instance Core.FromJSON Variant where
  parseJSON :: Value -> Parser Variant
parseJSON =
    String -> (Object -> Parser Variant) -> Value -> Parser Variant
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Variant"
      ( \Object
x ->
          Maybe Int -> Maybe Double -> Maybe Text -> Maybe Bool -> Variant
Variant'
            (Maybe Int -> Maybe Double -> Maybe Text -> Maybe Bool -> Variant)
-> Parser (Maybe Int)
-> Parser (Maybe Double -> Maybe Text -> Maybe Bool -> Variant)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"integerValue")
            Parser (Maybe Double -> Maybe Text -> Maybe Bool -> Variant)
-> Parser (Maybe Double)
-> Parser (Maybe Text -> Maybe Bool -> Variant)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"doubleValue")
            Parser (Maybe Text -> Maybe Bool -> Variant)
-> Parser (Maybe Text) -> Parser (Maybe Bool -> Variant)
forall (f :: * -> *) a b. Applicative f => 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
"stringValue")
            Parser (Maybe Bool -> Variant)
-> Parser (Maybe Bool) -> Parser Variant
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"booleanValue")
      )

instance Prelude.Hashable Variant

instance Prelude.NFData Variant

instance Core.ToJSON Variant where
  toJSON :: Variant -> Value
toJSON Variant' {Maybe Bool
Maybe Double
Maybe Int
Maybe Text
booleanValue :: Maybe Bool
stringValue :: Maybe Text
doubleValue :: Maybe Double
integerValue :: Maybe Int
$sel:booleanValue:Variant' :: Variant -> Maybe Bool
$sel:stringValue:Variant' :: Variant -> Maybe Text
$sel:doubleValue:Variant' :: Variant -> Maybe Double
$sel:integerValue:Variant' :: Variant -> Maybe Int
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"integerValue" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
integerValue,
            (Text
"doubleValue" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
doubleValue,
            (Text
"stringValue" 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
stringValue,
            (Text
"booleanValue" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
booleanValue
          ]
      )