{-# 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.CodeDeploy.Types.TimeBasedLinear
-- 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.CodeDeploy.Types.TimeBasedLinear 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

-- | A configuration that shifts traffic from one version of a Lambda
-- function or ECS task set to another in equal increments, with an equal
-- number of minutes between each increment. The original and target Lambda
-- function versions or ECS task sets are specified in the deployment\'s
-- AppSpec file.
--
-- /See:/ 'newTimeBasedLinear' smart constructor.
data TimeBasedLinear = TimeBasedLinear'
  { -- | The number of minutes between each incremental traffic shift of a
    -- @TimeBasedLinear@ deployment.
    TimeBasedLinear -> Maybe Int
linearInterval :: Prelude.Maybe Prelude.Int,
    -- | The percentage of traffic that is shifted at the start of each increment
    -- of a @TimeBasedLinear@ deployment.
    TimeBasedLinear -> Maybe Int
linearPercentage :: Prelude.Maybe Prelude.Int
  }
  deriving (TimeBasedLinear -> TimeBasedLinear -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TimeBasedLinear -> TimeBasedLinear -> Bool
$c/= :: TimeBasedLinear -> TimeBasedLinear -> Bool
== :: TimeBasedLinear -> TimeBasedLinear -> Bool
$c== :: TimeBasedLinear -> TimeBasedLinear -> Bool
Prelude.Eq, ReadPrec [TimeBasedLinear]
ReadPrec TimeBasedLinear
Int -> ReadS TimeBasedLinear
ReadS [TimeBasedLinear]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TimeBasedLinear]
$creadListPrec :: ReadPrec [TimeBasedLinear]
readPrec :: ReadPrec TimeBasedLinear
$creadPrec :: ReadPrec TimeBasedLinear
readList :: ReadS [TimeBasedLinear]
$creadList :: ReadS [TimeBasedLinear]
readsPrec :: Int -> ReadS TimeBasedLinear
$creadsPrec :: Int -> ReadS TimeBasedLinear
Prelude.Read, Int -> TimeBasedLinear -> ShowS
[TimeBasedLinear] -> ShowS
TimeBasedLinear -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TimeBasedLinear] -> ShowS
$cshowList :: [TimeBasedLinear] -> ShowS
show :: TimeBasedLinear -> String
$cshow :: TimeBasedLinear -> String
showsPrec :: Int -> TimeBasedLinear -> ShowS
$cshowsPrec :: Int -> TimeBasedLinear -> ShowS
Prelude.Show, forall x. Rep TimeBasedLinear x -> TimeBasedLinear
forall x. TimeBasedLinear -> Rep TimeBasedLinear x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TimeBasedLinear x -> TimeBasedLinear
$cfrom :: forall x. TimeBasedLinear -> Rep TimeBasedLinear x
Prelude.Generic)

-- |
-- Create a value of 'TimeBasedLinear' 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:
--
-- 'linearInterval', 'timeBasedLinear_linearInterval' - The number of minutes between each incremental traffic shift of a
-- @TimeBasedLinear@ deployment.
--
-- 'linearPercentage', 'timeBasedLinear_linearPercentage' - The percentage of traffic that is shifted at the start of each increment
-- of a @TimeBasedLinear@ deployment.
newTimeBasedLinear ::
  TimeBasedLinear
newTimeBasedLinear :: TimeBasedLinear
newTimeBasedLinear =
  TimeBasedLinear'
    { $sel:linearInterval:TimeBasedLinear' :: Maybe Int
linearInterval = forall a. Maybe a
Prelude.Nothing,
      $sel:linearPercentage:TimeBasedLinear' :: Maybe Int
linearPercentage = forall a. Maybe a
Prelude.Nothing
    }

-- | The number of minutes between each incremental traffic shift of a
-- @TimeBasedLinear@ deployment.
timeBasedLinear_linearInterval :: Lens.Lens' TimeBasedLinear (Prelude.Maybe Prelude.Int)
timeBasedLinear_linearInterval :: Lens' TimeBasedLinear (Maybe Int)
timeBasedLinear_linearInterval = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimeBasedLinear' {Maybe Int
linearInterval :: Maybe Int
$sel:linearInterval:TimeBasedLinear' :: TimeBasedLinear -> Maybe Int
linearInterval} -> Maybe Int
linearInterval) (\s :: TimeBasedLinear
s@TimeBasedLinear' {} Maybe Int
a -> TimeBasedLinear
s {$sel:linearInterval:TimeBasedLinear' :: Maybe Int
linearInterval = Maybe Int
a} :: TimeBasedLinear)

-- | The percentage of traffic that is shifted at the start of each increment
-- of a @TimeBasedLinear@ deployment.
timeBasedLinear_linearPercentage :: Lens.Lens' TimeBasedLinear (Prelude.Maybe Prelude.Int)
timeBasedLinear_linearPercentage :: Lens' TimeBasedLinear (Maybe Int)
timeBasedLinear_linearPercentage = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimeBasedLinear' {Maybe Int
linearPercentage :: Maybe Int
$sel:linearPercentage:TimeBasedLinear' :: TimeBasedLinear -> Maybe Int
linearPercentage} -> Maybe Int
linearPercentage) (\s :: TimeBasedLinear
s@TimeBasedLinear' {} Maybe Int
a -> TimeBasedLinear
s {$sel:linearPercentage:TimeBasedLinear' :: Maybe Int
linearPercentage = Maybe Int
a} :: TimeBasedLinear)

instance Data.FromJSON TimeBasedLinear where
  parseJSON :: Value -> Parser TimeBasedLinear
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"TimeBasedLinear"
      ( \Object
x ->
          Maybe Int -> Maybe Int -> TimeBasedLinear
TimeBasedLinear'
            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
"linearInterval")
            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
"linearPercentage")
      )

instance Prelude.Hashable TimeBasedLinear where
  hashWithSalt :: Int -> TimeBasedLinear -> Int
hashWithSalt Int
_salt TimeBasedLinear' {Maybe Int
linearPercentage :: Maybe Int
linearInterval :: Maybe Int
$sel:linearPercentage:TimeBasedLinear' :: TimeBasedLinear -> Maybe Int
$sel:linearInterval:TimeBasedLinear' :: TimeBasedLinear -> Maybe Int
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
linearInterval
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
linearPercentage

instance Prelude.NFData TimeBasedLinear where
  rnf :: TimeBasedLinear -> ()
rnf TimeBasedLinear' {Maybe Int
linearPercentage :: Maybe Int
linearInterval :: Maybe Int
$sel:linearPercentage:TimeBasedLinear' :: TimeBasedLinear -> Maybe Int
$sel:linearInterval:TimeBasedLinear' :: TimeBasedLinear -> Maybe Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
linearInterval
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
linearPercentage

instance Data.ToJSON TimeBasedLinear where
  toJSON :: TimeBasedLinear -> Value
toJSON TimeBasedLinear' {Maybe Int
linearPercentage :: Maybe Int
linearInterval :: Maybe Int
$sel:linearPercentage:TimeBasedLinear' :: TimeBasedLinear -> Maybe Int
$sel:linearInterval:TimeBasedLinear' :: TimeBasedLinear -> Maybe Int
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"linearInterval" 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 Int
linearInterval,
            (Key
"linearPercentage" 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 Int
linearPercentage
          ]
      )