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

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

-- | Describes the percentile and percentile value.
--
-- /See:/ 'newPercentPair' smart constructor.
data PercentPair = PercentPair'
  { -- | The value of the percentile.
    PercentPair -> Maybe Double
value :: Prelude.Maybe Prelude.Double,
    -- | The percentile.
    PercentPair -> Maybe Double
percent :: Prelude.Maybe Prelude.Double
  }
  deriving (PercentPair -> PercentPair -> Bool
(PercentPair -> PercentPair -> Bool)
-> (PercentPair -> PercentPair -> Bool) -> Eq PercentPair
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PercentPair -> PercentPair -> Bool
$c/= :: PercentPair -> PercentPair -> Bool
== :: PercentPair -> PercentPair -> Bool
$c== :: PercentPair -> PercentPair -> Bool
Prelude.Eq, ReadPrec [PercentPair]
ReadPrec PercentPair
Int -> ReadS PercentPair
ReadS [PercentPair]
(Int -> ReadS PercentPair)
-> ReadS [PercentPair]
-> ReadPrec PercentPair
-> ReadPrec [PercentPair]
-> Read PercentPair
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PercentPair]
$creadListPrec :: ReadPrec [PercentPair]
readPrec :: ReadPrec PercentPair
$creadPrec :: ReadPrec PercentPair
readList :: ReadS [PercentPair]
$creadList :: ReadS [PercentPair]
readsPrec :: Int -> ReadS PercentPair
$creadsPrec :: Int -> ReadS PercentPair
Prelude.Read, Int -> PercentPair -> ShowS
[PercentPair] -> ShowS
PercentPair -> String
(Int -> PercentPair -> ShowS)
-> (PercentPair -> String)
-> ([PercentPair] -> ShowS)
-> Show PercentPair
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PercentPair] -> ShowS
$cshowList :: [PercentPair] -> ShowS
show :: PercentPair -> String
$cshow :: PercentPair -> String
showsPrec :: Int -> PercentPair -> ShowS
$cshowsPrec :: Int -> PercentPair -> ShowS
Prelude.Show, (forall x. PercentPair -> Rep PercentPair x)
-> (forall x. Rep PercentPair x -> PercentPair)
-> Generic PercentPair
forall x. Rep PercentPair x -> PercentPair
forall x. PercentPair -> Rep PercentPair x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PercentPair x -> PercentPair
$cfrom :: forall x. PercentPair -> Rep PercentPair x
Prelude.Generic)

-- |
-- Create a value of 'PercentPair' 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:
--
-- 'value', 'percentPair_value' - The value of the percentile.
--
-- 'percent', 'percentPair_percent' - The percentile.
newPercentPair ::
  PercentPair
newPercentPair :: PercentPair
newPercentPair =
  PercentPair' :: Maybe Double -> Maybe Double -> PercentPair
PercentPair'
    { $sel:value:PercentPair' :: Maybe Double
value = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:percent:PercentPair' :: Maybe Double
percent = Maybe Double
forall a. Maybe a
Prelude.Nothing
    }

-- | The value of the percentile.
percentPair_value :: Lens.Lens' PercentPair (Prelude.Maybe Prelude.Double)
percentPair_value :: (Maybe Double -> f (Maybe Double)) -> PercentPair -> f PercentPair
percentPair_value = (PercentPair -> Maybe Double)
-> (PercentPair -> Maybe Double -> PercentPair)
-> Lens PercentPair PercentPair (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PercentPair' {Maybe Double
value :: Maybe Double
$sel:value:PercentPair' :: PercentPair -> Maybe Double
value} -> Maybe Double
value) (\s :: PercentPair
s@PercentPair' {} Maybe Double
a -> PercentPair
s {$sel:value:PercentPair' :: Maybe Double
value = Maybe Double
a} :: PercentPair)

-- | The percentile.
percentPair_percent :: Lens.Lens' PercentPair (Prelude.Maybe Prelude.Double)
percentPair_percent :: (Maybe Double -> f (Maybe Double)) -> PercentPair -> f PercentPair
percentPair_percent = (PercentPair -> Maybe Double)
-> (PercentPair -> Maybe Double -> PercentPair)
-> Lens PercentPair PercentPair (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PercentPair' {Maybe Double
percent :: Maybe Double
$sel:percent:PercentPair' :: PercentPair -> Maybe Double
percent} -> Maybe Double
percent) (\s :: PercentPair
s@PercentPair' {} Maybe Double
a -> PercentPair
s {$sel:percent:PercentPair' :: Maybe Double
percent = Maybe Double
a} :: PercentPair)

instance Core.FromJSON PercentPair where
  parseJSON :: Value -> Parser PercentPair
parseJSON =
    String
-> (Object -> Parser PercentPair) -> Value -> Parser PercentPair
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PercentPair"
      ( \Object
x ->
          Maybe Double -> Maybe Double -> PercentPair
PercentPair'
            (Maybe Double -> Maybe Double -> PercentPair)
-> Parser (Maybe Double) -> Parser (Maybe Double -> PercentPair)
forall (f :: * -> *) a b. Functor 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
"value")
            Parser (Maybe Double -> PercentPair)
-> Parser (Maybe Double) -> Parser PercentPair
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
"percent")
      )

instance Prelude.Hashable PercentPair

instance Prelude.NFData PercentPair