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

-- | The value to be compared with the @metric@.
--
-- /See:/ 'newMetricValue' smart constructor.
data MetricValue = MetricValue'
  { -- | If the @comparisonOperator@ calls for a set of CIDRs, use this to
    -- specify that set to be compared with the @metric@.
    MetricValue -> Maybe [Text]
cidrs :: Prelude.Maybe [Prelude.Text],
    -- | If the @comparisonOperator@ calls for a numeric value, use this to
    -- specify that numeric value to be compared with the @metric@.
    MetricValue -> Maybe Natural
count :: Prelude.Maybe Prelude.Natural,
    -- | The numeral value of a metric.
    MetricValue -> Maybe Double
number :: Prelude.Maybe Prelude.Double,
    -- | The numeral values of a metric.
    MetricValue -> Maybe [Double]
numbers :: Prelude.Maybe [Prelude.Double],
    -- | If the @comparisonOperator@ calls for a set of ports, use this to
    -- specify that set to be compared with the @metric@.
    MetricValue -> Maybe [Natural]
ports :: Prelude.Maybe [Prelude.Natural],
    -- | The string values of a metric.
    MetricValue -> Maybe [Text]
strings :: Prelude.Maybe [Prelude.Text]
  }
  deriving (MetricValue -> MetricValue -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricValue -> MetricValue -> Bool
$c/= :: MetricValue -> MetricValue -> Bool
== :: MetricValue -> MetricValue -> Bool
$c== :: MetricValue -> MetricValue -> Bool
Prelude.Eq, ReadPrec [MetricValue]
ReadPrec MetricValue
Int -> ReadS MetricValue
ReadS [MetricValue]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricValue]
$creadListPrec :: ReadPrec [MetricValue]
readPrec :: ReadPrec MetricValue
$creadPrec :: ReadPrec MetricValue
readList :: ReadS [MetricValue]
$creadList :: ReadS [MetricValue]
readsPrec :: Int -> ReadS MetricValue
$creadsPrec :: Int -> ReadS MetricValue
Prelude.Read, Int -> MetricValue -> ShowS
[MetricValue] -> ShowS
MetricValue -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricValue] -> ShowS
$cshowList :: [MetricValue] -> ShowS
show :: MetricValue -> String
$cshow :: MetricValue -> String
showsPrec :: Int -> MetricValue -> ShowS
$cshowsPrec :: Int -> MetricValue -> ShowS
Prelude.Show, forall x. Rep MetricValue x -> MetricValue
forall x. MetricValue -> Rep MetricValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricValue x -> MetricValue
$cfrom :: forall x. MetricValue -> Rep MetricValue x
Prelude.Generic)

-- |
-- Create a value of 'MetricValue' 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:
--
-- 'cidrs', 'metricValue_cidrs' - If the @comparisonOperator@ calls for a set of CIDRs, use this to
-- specify that set to be compared with the @metric@.
--
-- 'count', 'metricValue_count' - If the @comparisonOperator@ calls for a numeric value, use this to
-- specify that numeric value to be compared with the @metric@.
--
-- 'number', 'metricValue_number' - The numeral value of a metric.
--
-- 'numbers', 'metricValue_numbers' - The numeral values of a metric.
--
-- 'ports', 'metricValue_ports' - If the @comparisonOperator@ calls for a set of ports, use this to
-- specify that set to be compared with the @metric@.
--
-- 'strings', 'metricValue_strings' - The string values of a metric.
newMetricValue ::
  MetricValue
newMetricValue :: MetricValue
newMetricValue =
  MetricValue'
    { $sel:cidrs:MetricValue' :: Maybe [Text]
cidrs = forall a. Maybe a
Prelude.Nothing,
      $sel:count:MetricValue' :: Maybe Natural
count = forall a. Maybe a
Prelude.Nothing,
      $sel:number:MetricValue' :: Maybe Double
number = forall a. Maybe a
Prelude.Nothing,
      $sel:numbers:MetricValue' :: Maybe [Double]
numbers = forall a. Maybe a
Prelude.Nothing,
      $sel:ports:MetricValue' :: Maybe [Natural]
ports = forall a. Maybe a
Prelude.Nothing,
      $sel:strings:MetricValue' :: Maybe [Text]
strings = forall a. Maybe a
Prelude.Nothing
    }

-- | If the @comparisonOperator@ calls for a set of CIDRs, use this to
-- specify that set to be compared with the @metric@.
metricValue_cidrs :: Lens.Lens' MetricValue (Prelude.Maybe [Prelude.Text])
metricValue_cidrs :: Lens' MetricValue (Maybe [Text])
metricValue_cidrs = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricValue' {Maybe [Text]
cidrs :: Maybe [Text]
$sel:cidrs:MetricValue' :: MetricValue -> Maybe [Text]
cidrs} -> Maybe [Text]
cidrs) (\s :: MetricValue
s@MetricValue' {} Maybe [Text]
a -> MetricValue
s {$sel:cidrs:MetricValue' :: Maybe [Text]
cidrs = Maybe [Text]
a} :: MetricValue) 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | If the @comparisonOperator@ calls for a numeric value, use this to
-- specify that numeric value to be compared with the @metric@.
metricValue_count :: Lens.Lens' MetricValue (Prelude.Maybe Prelude.Natural)
metricValue_count :: Lens' MetricValue (Maybe Natural)
metricValue_count = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricValue' {Maybe Natural
count :: Maybe Natural
$sel:count:MetricValue' :: MetricValue -> Maybe Natural
count} -> Maybe Natural
count) (\s :: MetricValue
s@MetricValue' {} Maybe Natural
a -> MetricValue
s {$sel:count:MetricValue' :: Maybe Natural
count = Maybe Natural
a} :: MetricValue)

-- | The numeral value of a metric.
metricValue_number :: Lens.Lens' MetricValue (Prelude.Maybe Prelude.Double)
metricValue_number :: Lens' MetricValue (Maybe Double)
metricValue_number = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricValue' {Maybe Double
number :: Maybe Double
$sel:number:MetricValue' :: MetricValue -> Maybe Double
number} -> Maybe Double
number) (\s :: MetricValue
s@MetricValue' {} Maybe Double
a -> MetricValue
s {$sel:number:MetricValue' :: Maybe Double
number = Maybe Double
a} :: MetricValue)

-- | The numeral values of a metric.
metricValue_numbers :: Lens.Lens' MetricValue (Prelude.Maybe [Prelude.Double])
metricValue_numbers :: Lens' MetricValue (Maybe [Double])
metricValue_numbers = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricValue' {Maybe [Double]
numbers :: Maybe [Double]
$sel:numbers:MetricValue' :: MetricValue -> Maybe [Double]
numbers} -> Maybe [Double]
numbers) (\s :: MetricValue
s@MetricValue' {} Maybe [Double]
a -> MetricValue
s {$sel:numbers:MetricValue' :: Maybe [Double]
numbers = Maybe [Double]
a} :: MetricValue) 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | If the @comparisonOperator@ calls for a set of ports, use this to
-- specify that set to be compared with the @metric@.
metricValue_ports :: Lens.Lens' MetricValue (Prelude.Maybe [Prelude.Natural])
metricValue_ports :: Lens' MetricValue (Maybe [Natural])
metricValue_ports = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricValue' {Maybe [Natural]
ports :: Maybe [Natural]
$sel:ports:MetricValue' :: MetricValue -> Maybe [Natural]
ports} -> Maybe [Natural]
ports) (\s :: MetricValue
s@MetricValue' {} Maybe [Natural]
a -> MetricValue
s {$sel:ports:MetricValue' :: Maybe [Natural]
ports = Maybe [Natural]
a} :: MetricValue) 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The string values of a metric.
metricValue_strings :: Lens.Lens' MetricValue (Prelude.Maybe [Prelude.Text])
metricValue_strings :: Lens' MetricValue (Maybe [Text])
metricValue_strings = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricValue' {Maybe [Text]
strings :: Maybe [Text]
$sel:strings:MetricValue' :: MetricValue -> Maybe [Text]
strings} -> Maybe [Text]
strings) (\s :: MetricValue
s@MetricValue' {} Maybe [Text]
a -> MetricValue
s {$sel:strings:MetricValue' :: Maybe [Text]
strings = Maybe [Text]
a} :: MetricValue) 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON MetricValue where
  parseJSON :: Value -> Parser MetricValue
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"MetricValue"
      ( \Object
x ->
          Maybe [Text]
-> Maybe Natural
-> Maybe Double
-> Maybe [Double]
-> Maybe [Natural]
-> Maybe [Text]
-> MetricValue
MetricValue'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"cidrs" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"count")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"number")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"numbers" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"ports" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"strings" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable MetricValue where
  hashWithSalt :: Int -> MetricValue -> Int
hashWithSalt Int
_salt MetricValue' {Maybe Double
Maybe Natural
Maybe [Double]
Maybe [Natural]
Maybe [Text]
strings :: Maybe [Text]
ports :: Maybe [Natural]
numbers :: Maybe [Double]
number :: Maybe Double
count :: Maybe Natural
cidrs :: Maybe [Text]
$sel:strings:MetricValue' :: MetricValue -> Maybe [Text]
$sel:ports:MetricValue' :: MetricValue -> Maybe [Natural]
$sel:numbers:MetricValue' :: MetricValue -> Maybe [Double]
$sel:number:MetricValue' :: MetricValue -> Maybe Double
$sel:count:MetricValue' :: MetricValue -> Maybe Natural
$sel:cidrs:MetricValue' :: MetricValue -> Maybe [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
cidrs
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
count
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
number
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Double]
numbers
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Natural]
ports
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
strings

instance Prelude.NFData MetricValue where
  rnf :: MetricValue -> ()
rnf MetricValue' {Maybe Double
Maybe Natural
Maybe [Double]
Maybe [Natural]
Maybe [Text]
strings :: Maybe [Text]
ports :: Maybe [Natural]
numbers :: Maybe [Double]
number :: Maybe Double
count :: Maybe Natural
cidrs :: Maybe [Text]
$sel:strings:MetricValue' :: MetricValue -> Maybe [Text]
$sel:ports:MetricValue' :: MetricValue -> Maybe [Natural]
$sel:numbers:MetricValue' :: MetricValue -> Maybe [Double]
$sel:number:MetricValue' :: MetricValue -> Maybe Double
$sel:count:MetricValue' :: MetricValue -> Maybe Natural
$sel:cidrs:MetricValue' :: MetricValue -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
cidrs
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
count
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
number
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Double]
numbers
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Natural]
ports
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
strings

instance Data.ToJSON MetricValue where
  toJSON :: MetricValue -> Value
toJSON MetricValue' {Maybe Double
Maybe Natural
Maybe [Double]
Maybe [Natural]
Maybe [Text]
strings :: Maybe [Text]
ports :: Maybe [Natural]
numbers :: Maybe [Double]
number :: Maybe Double
count :: Maybe Natural
cidrs :: Maybe [Text]
$sel:strings:MetricValue' :: MetricValue -> Maybe [Text]
$sel:ports:MetricValue' :: MetricValue -> Maybe [Natural]
$sel:numbers:MetricValue' :: MetricValue -> Maybe [Double]
$sel:number:MetricValue' :: MetricValue -> Maybe Double
$sel:count:MetricValue' :: MetricValue -> Maybe Natural
$sel:cidrs:MetricValue' :: MetricValue -> Maybe [Text]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"cidrs" 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]
cidrs,
            (Key
"count" 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 Natural
count,
            (Key
"number" 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 Double
number,
            (Key
"numbers" 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 [Double]
numbers,
            (Key
"ports" 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 [Natural]
ports,
            (Key
"strings" 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]
strings
          ]
      )