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

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.RateIncreaseCriteria
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Allows you to create an exponential rate of rollout for a job.
--
-- /See:/ 'newExponentialRolloutRate' smart constructor.
data ExponentialRolloutRate = ExponentialRolloutRate'
  { -- | The minimum number of things that will be notified of a pending job, per
    -- minute at the start of job rollout. This parameter allows you to define
    -- the initial rate of rollout.
    ExponentialRolloutRate -> Natural
baseRatePerMinute :: Prelude.Natural,
    -- | The exponential factor to increase the rate of rollout for a job.
    --
    -- Amazon Web Services IoT Core supports up to one digit after the decimal
    -- (for example, 1.5, but not 1.55).
    ExponentialRolloutRate -> Double
incrementFactor :: Prelude.Double,
    -- | The criteria to initiate the increase in rate of rollout for a job.
    ExponentialRolloutRate -> RateIncreaseCriteria
rateIncreaseCriteria :: RateIncreaseCriteria
  }
  deriving (ExponentialRolloutRate -> ExponentialRolloutRate -> Bool
(ExponentialRolloutRate -> ExponentialRolloutRate -> Bool)
-> (ExponentialRolloutRate -> ExponentialRolloutRate -> Bool)
-> Eq ExponentialRolloutRate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExponentialRolloutRate -> ExponentialRolloutRate -> Bool
$c/= :: ExponentialRolloutRate -> ExponentialRolloutRate -> Bool
== :: ExponentialRolloutRate -> ExponentialRolloutRate -> Bool
$c== :: ExponentialRolloutRate -> ExponentialRolloutRate -> Bool
Prelude.Eq, ReadPrec [ExponentialRolloutRate]
ReadPrec ExponentialRolloutRate
Int -> ReadS ExponentialRolloutRate
ReadS [ExponentialRolloutRate]
(Int -> ReadS ExponentialRolloutRate)
-> ReadS [ExponentialRolloutRate]
-> ReadPrec ExponentialRolloutRate
-> ReadPrec [ExponentialRolloutRate]
-> Read ExponentialRolloutRate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ExponentialRolloutRate]
$creadListPrec :: ReadPrec [ExponentialRolloutRate]
readPrec :: ReadPrec ExponentialRolloutRate
$creadPrec :: ReadPrec ExponentialRolloutRate
readList :: ReadS [ExponentialRolloutRate]
$creadList :: ReadS [ExponentialRolloutRate]
readsPrec :: Int -> ReadS ExponentialRolloutRate
$creadsPrec :: Int -> ReadS ExponentialRolloutRate
Prelude.Read, Int -> ExponentialRolloutRate -> ShowS
[ExponentialRolloutRate] -> ShowS
ExponentialRolloutRate -> String
(Int -> ExponentialRolloutRate -> ShowS)
-> (ExponentialRolloutRate -> String)
-> ([ExponentialRolloutRate] -> ShowS)
-> Show ExponentialRolloutRate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExponentialRolloutRate] -> ShowS
$cshowList :: [ExponentialRolloutRate] -> ShowS
show :: ExponentialRolloutRate -> String
$cshow :: ExponentialRolloutRate -> String
showsPrec :: Int -> ExponentialRolloutRate -> ShowS
$cshowsPrec :: Int -> ExponentialRolloutRate -> ShowS
Prelude.Show, (forall x. ExponentialRolloutRate -> Rep ExponentialRolloutRate x)
-> (forall x.
    Rep ExponentialRolloutRate x -> ExponentialRolloutRate)
-> Generic ExponentialRolloutRate
forall x. Rep ExponentialRolloutRate x -> ExponentialRolloutRate
forall x. ExponentialRolloutRate -> Rep ExponentialRolloutRate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ExponentialRolloutRate x -> ExponentialRolloutRate
$cfrom :: forall x. ExponentialRolloutRate -> Rep ExponentialRolloutRate x
Prelude.Generic)

-- |
-- Create a value of 'ExponentialRolloutRate' 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:
--
-- 'baseRatePerMinute', 'exponentialRolloutRate_baseRatePerMinute' - The minimum number of things that will be notified of a pending job, per
-- minute at the start of job rollout. This parameter allows you to define
-- the initial rate of rollout.
--
-- 'incrementFactor', 'exponentialRolloutRate_incrementFactor' - The exponential factor to increase the rate of rollout for a job.
--
-- Amazon Web Services IoT Core supports up to one digit after the decimal
-- (for example, 1.5, but not 1.55).
--
-- 'rateIncreaseCriteria', 'exponentialRolloutRate_rateIncreaseCriteria' - The criteria to initiate the increase in rate of rollout for a job.
newExponentialRolloutRate ::
  -- | 'baseRatePerMinute'
  Prelude.Natural ->
  -- | 'incrementFactor'
  Prelude.Double ->
  -- | 'rateIncreaseCriteria'
  RateIncreaseCriteria ->
  ExponentialRolloutRate
newExponentialRolloutRate :: Natural -> Double -> RateIncreaseCriteria -> ExponentialRolloutRate
newExponentialRolloutRate
  Natural
pBaseRatePerMinute_
  Double
pIncrementFactor_
  RateIncreaseCriteria
pRateIncreaseCriteria_ =
    ExponentialRolloutRate' :: Natural -> Double -> RateIncreaseCriteria -> ExponentialRolloutRate
ExponentialRolloutRate'
      { $sel:baseRatePerMinute:ExponentialRolloutRate' :: Natural
baseRatePerMinute =
          Natural
pBaseRatePerMinute_,
        $sel:incrementFactor:ExponentialRolloutRate' :: Double
incrementFactor = Double
pIncrementFactor_,
        $sel:rateIncreaseCriteria:ExponentialRolloutRate' :: RateIncreaseCriteria
rateIncreaseCriteria = RateIncreaseCriteria
pRateIncreaseCriteria_
      }

-- | The minimum number of things that will be notified of a pending job, per
-- minute at the start of job rollout. This parameter allows you to define
-- the initial rate of rollout.
exponentialRolloutRate_baseRatePerMinute :: Lens.Lens' ExponentialRolloutRate Prelude.Natural
exponentialRolloutRate_baseRatePerMinute :: (Natural -> f Natural)
-> ExponentialRolloutRate -> f ExponentialRolloutRate
exponentialRolloutRate_baseRatePerMinute = (ExponentialRolloutRate -> Natural)
-> (ExponentialRolloutRate -> Natural -> ExponentialRolloutRate)
-> Lens
     ExponentialRolloutRate ExponentialRolloutRate Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExponentialRolloutRate' {Natural
baseRatePerMinute :: Natural
$sel:baseRatePerMinute:ExponentialRolloutRate' :: ExponentialRolloutRate -> Natural
baseRatePerMinute} -> Natural
baseRatePerMinute) (\s :: ExponentialRolloutRate
s@ExponentialRolloutRate' {} Natural
a -> ExponentialRolloutRate
s {$sel:baseRatePerMinute:ExponentialRolloutRate' :: Natural
baseRatePerMinute = Natural
a} :: ExponentialRolloutRate)

-- | The exponential factor to increase the rate of rollout for a job.
--
-- Amazon Web Services IoT Core supports up to one digit after the decimal
-- (for example, 1.5, but not 1.55).
exponentialRolloutRate_incrementFactor :: Lens.Lens' ExponentialRolloutRate Prelude.Double
exponentialRolloutRate_incrementFactor :: (Double -> f Double)
-> ExponentialRolloutRate -> f ExponentialRolloutRate
exponentialRolloutRate_incrementFactor = (ExponentialRolloutRate -> Double)
-> (ExponentialRolloutRate -> Double -> ExponentialRolloutRate)
-> Lens ExponentialRolloutRate ExponentialRolloutRate Double Double
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExponentialRolloutRate' {Double
incrementFactor :: Double
$sel:incrementFactor:ExponentialRolloutRate' :: ExponentialRolloutRate -> Double
incrementFactor} -> Double
incrementFactor) (\s :: ExponentialRolloutRate
s@ExponentialRolloutRate' {} Double
a -> ExponentialRolloutRate
s {$sel:incrementFactor:ExponentialRolloutRate' :: Double
incrementFactor = Double
a} :: ExponentialRolloutRate)

-- | The criteria to initiate the increase in rate of rollout for a job.
exponentialRolloutRate_rateIncreaseCriteria :: Lens.Lens' ExponentialRolloutRate RateIncreaseCriteria
exponentialRolloutRate_rateIncreaseCriteria :: (RateIncreaseCriteria -> f RateIncreaseCriteria)
-> ExponentialRolloutRate -> f ExponentialRolloutRate
exponentialRolloutRate_rateIncreaseCriteria = (ExponentialRolloutRate -> RateIncreaseCriteria)
-> (ExponentialRolloutRate
    -> RateIncreaseCriteria -> ExponentialRolloutRate)
-> Lens
     ExponentialRolloutRate
     ExponentialRolloutRate
     RateIncreaseCriteria
     RateIncreaseCriteria
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExponentialRolloutRate' {RateIncreaseCriteria
rateIncreaseCriteria :: RateIncreaseCriteria
$sel:rateIncreaseCriteria:ExponentialRolloutRate' :: ExponentialRolloutRate -> RateIncreaseCriteria
rateIncreaseCriteria} -> RateIncreaseCriteria
rateIncreaseCriteria) (\s :: ExponentialRolloutRate
s@ExponentialRolloutRate' {} RateIncreaseCriteria
a -> ExponentialRolloutRate
s {$sel:rateIncreaseCriteria:ExponentialRolloutRate' :: RateIncreaseCriteria
rateIncreaseCriteria = RateIncreaseCriteria
a} :: ExponentialRolloutRate)

instance Core.FromJSON ExponentialRolloutRate where
  parseJSON :: Value -> Parser ExponentialRolloutRate
parseJSON =
    String
-> (Object -> Parser ExponentialRolloutRate)
-> Value
-> Parser ExponentialRolloutRate
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ExponentialRolloutRate"
      ( \Object
x ->
          Natural -> Double -> RateIncreaseCriteria -> ExponentialRolloutRate
ExponentialRolloutRate'
            (Natural
 -> Double -> RateIncreaseCriteria -> ExponentialRolloutRate)
-> Parser Natural
-> Parser
     (Double -> RateIncreaseCriteria -> ExponentialRolloutRate)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"baseRatePerMinute")
            Parser (Double -> RateIncreaseCriteria -> ExponentialRolloutRate)
-> Parser Double
-> Parser (RateIncreaseCriteria -> ExponentialRolloutRate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Double
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"incrementFactor")
            Parser (RateIncreaseCriteria -> ExponentialRolloutRate)
-> Parser RateIncreaseCriteria -> Parser ExponentialRolloutRate
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser RateIncreaseCriteria
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"rateIncreaseCriteria")
      )

instance Prelude.Hashable ExponentialRolloutRate

instance Prelude.NFData ExponentialRolloutRate

instance Core.ToJSON ExponentialRolloutRate where
  toJSON :: ExponentialRolloutRate -> Value
toJSON ExponentialRolloutRate' {Double
Natural
RateIncreaseCriteria
rateIncreaseCriteria :: RateIncreaseCriteria
incrementFactor :: Double
baseRatePerMinute :: Natural
$sel:rateIncreaseCriteria:ExponentialRolloutRate' :: ExponentialRolloutRate -> RateIncreaseCriteria
$sel:incrementFactor:ExponentialRolloutRate' :: ExponentialRolloutRate -> Double
$sel:baseRatePerMinute:ExponentialRolloutRate' :: ExponentialRolloutRate -> Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"baseRatePerMinute" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
baseRatePerMinute),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"incrementFactor" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Double
incrementFactor),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"rateIncreaseCriteria"
                  Text -> RateIncreaseCriteria -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= RateIncreaseCriteria
rateIncreaseCriteria
              )
          ]
      )