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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(TimeBasedLinear -> TimeBasedLinear -> Bool)
-> (TimeBasedLinear -> TimeBasedLinear -> Bool)
-> Eq TimeBasedLinear
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]
(Int -> ReadS TimeBasedLinear)
-> ReadS [TimeBasedLinear]
-> ReadPrec TimeBasedLinear
-> ReadPrec [TimeBasedLinear]
-> Read 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
(Int -> TimeBasedLinear -> ShowS)
-> (TimeBasedLinear -> String)
-> ([TimeBasedLinear] -> ShowS)
-> Show TimeBasedLinear
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. TimeBasedLinear -> Rep TimeBasedLinear x)
-> (forall x. Rep TimeBasedLinear x -> TimeBasedLinear)
-> Generic TimeBasedLinear
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' :: Maybe Int -> Maybe Int -> TimeBasedLinear
TimeBasedLinear'
    { $sel:linearInterval:TimeBasedLinear' :: Maybe Int
linearInterval = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:linearPercentage:TimeBasedLinear' :: Maybe Int
linearPercentage = Maybe Int
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 :: (Maybe Int -> f (Maybe Int))
-> TimeBasedLinear -> f TimeBasedLinear
timeBasedLinear_linearInterval = (TimeBasedLinear -> Maybe Int)
-> (TimeBasedLinear -> Maybe Int -> TimeBasedLinear)
-> Lens TimeBasedLinear TimeBasedLinear (Maybe Int) (Maybe Int)
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 :: (Maybe Int -> f (Maybe Int))
-> TimeBasedLinear -> f TimeBasedLinear
timeBasedLinear_linearPercentage = (TimeBasedLinear -> Maybe Int)
-> (TimeBasedLinear -> Maybe Int -> TimeBasedLinear)
-> Lens TimeBasedLinear TimeBasedLinear (Maybe Int) (Maybe Int)
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 Core.FromJSON TimeBasedLinear where
  parseJSON :: Value -> Parser TimeBasedLinear
parseJSON =
    String
-> (Object -> Parser TimeBasedLinear)
-> Value
-> Parser TimeBasedLinear
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TimeBasedLinear"
      ( \Object
x ->
          Maybe Int -> Maybe Int -> TimeBasedLinear
TimeBasedLinear'
            (Maybe Int -> Maybe Int -> TimeBasedLinear)
-> Parser (Maybe Int) -> Parser (Maybe Int -> TimeBasedLinear)
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
"linearInterval")
            Parser (Maybe Int -> TimeBasedLinear)
-> Parser (Maybe Int) -> Parser TimeBasedLinear
forall (f :: * -> *) a b. Applicative f => 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
"linearPercentage")
      )

instance Prelude.Hashable TimeBasedLinear

instance Prelude.NFData TimeBasedLinear

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"linearInterval" 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
linearInterval,
            (Text
"linearPercentage" 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
linearPercentage
          ]
      )