{-# 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.TimeBasedCanary
-- 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.TimeBasedCanary 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 two increments. The original and
-- target Lambda function versions or ECS task sets are specified in the
-- deployment\'s AppSpec file.
--
-- /See:/ 'newTimeBasedCanary' smart constructor.
data TimeBasedCanary = TimeBasedCanary'
  { -- | The number of minutes between the first and second traffic shifts of a
    -- @TimeBasedCanary@ deployment.
    TimeBasedCanary -> Maybe Int
canaryInterval :: Prelude.Maybe Prelude.Int,
    -- | The percentage of traffic to shift in the first increment of a
    -- @TimeBasedCanary@ deployment.
    TimeBasedCanary -> Maybe Int
canaryPercentage :: Prelude.Maybe Prelude.Int
  }
  deriving (TimeBasedCanary -> TimeBasedCanary -> Bool
(TimeBasedCanary -> TimeBasedCanary -> Bool)
-> (TimeBasedCanary -> TimeBasedCanary -> Bool)
-> Eq TimeBasedCanary
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TimeBasedCanary -> TimeBasedCanary -> Bool
$c/= :: TimeBasedCanary -> TimeBasedCanary -> Bool
== :: TimeBasedCanary -> TimeBasedCanary -> Bool
$c== :: TimeBasedCanary -> TimeBasedCanary -> Bool
Prelude.Eq, ReadPrec [TimeBasedCanary]
ReadPrec TimeBasedCanary
Int -> ReadS TimeBasedCanary
ReadS [TimeBasedCanary]
(Int -> ReadS TimeBasedCanary)
-> ReadS [TimeBasedCanary]
-> ReadPrec TimeBasedCanary
-> ReadPrec [TimeBasedCanary]
-> Read TimeBasedCanary
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TimeBasedCanary]
$creadListPrec :: ReadPrec [TimeBasedCanary]
readPrec :: ReadPrec TimeBasedCanary
$creadPrec :: ReadPrec TimeBasedCanary
readList :: ReadS [TimeBasedCanary]
$creadList :: ReadS [TimeBasedCanary]
readsPrec :: Int -> ReadS TimeBasedCanary
$creadsPrec :: Int -> ReadS TimeBasedCanary
Prelude.Read, Int -> TimeBasedCanary -> ShowS
[TimeBasedCanary] -> ShowS
TimeBasedCanary -> String
(Int -> TimeBasedCanary -> ShowS)
-> (TimeBasedCanary -> String)
-> ([TimeBasedCanary] -> ShowS)
-> Show TimeBasedCanary
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TimeBasedCanary] -> ShowS
$cshowList :: [TimeBasedCanary] -> ShowS
show :: TimeBasedCanary -> String
$cshow :: TimeBasedCanary -> String
showsPrec :: Int -> TimeBasedCanary -> ShowS
$cshowsPrec :: Int -> TimeBasedCanary -> ShowS
Prelude.Show, (forall x. TimeBasedCanary -> Rep TimeBasedCanary x)
-> (forall x. Rep TimeBasedCanary x -> TimeBasedCanary)
-> Generic TimeBasedCanary
forall x. Rep TimeBasedCanary x -> TimeBasedCanary
forall x. TimeBasedCanary -> Rep TimeBasedCanary x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TimeBasedCanary x -> TimeBasedCanary
$cfrom :: forall x. TimeBasedCanary -> Rep TimeBasedCanary x
Prelude.Generic)

-- |
-- Create a value of 'TimeBasedCanary' 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:
--
-- 'canaryInterval', 'timeBasedCanary_canaryInterval' - The number of minutes between the first and second traffic shifts of a
-- @TimeBasedCanary@ deployment.
--
-- 'canaryPercentage', 'timeBasedCanary_canaryPercentage' - The percentage of traffic to shift in the first increment of a
-- @TimeBasedCanary@ deployment.
newTimeBasedCanary ::
  TimeBasedCanary
newTimeBasedCanary :: TimeBasedCanary
newTimeBasedCanary =
  TimeBasedCanary' :: Maybe Int -> Maybe Int -> TimeBasedCanary
TimeBasedCanary'
    { $sel:canaryInterval:TimeBasedCanary' :: Maybe Int
canaryInterval = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:canaryPercentage:TimeBasedCanary' :: Maybe Int
canaryPercentage = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | The number of minutes between the first and second traffic shifts of a
-- @TimeBasedCanary@ deployment.
timeBasedCanary_canaryInterval :: Lens.Lens' TimeBasedCanary (Prelude.Maybe Prelude.Int)
timeBasedCanary_canaryInterval :: (Maybe Int -> f (Maybe Int))
-> TimeBasedCanary -> f TimeBasedCanary
timeBasedCanary_canaryInterval = (TimeBasedCanary -> Maybe Int)
-> (TimeBasedCanary -> Maybe Int -> TimeBasedCanary)
-> Lens TimeBasedCanary TimeBasedCanary (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimeBasedCanary' {Maybe Int
canaryInterval :: Maybe Int
$sel:canaryInterval:TimeBasedCanary' :: TimeBasedCanary -> Maybe Int
canaryInterval} -> Maybe Int
canaryInterval) (\s :: TimeBasedCanary
s@TimeBasedCanary' {} Maybe Int
a -> TimeBasedCanary
s {$sel:canaryInterval:TimeBasedCanary' :: Maybe Int
canaryInterval = Maybe Int
a} :: TimeBasedCanary)

-- | The percentage of traffic to shift in the first increment of a
-- @TimeBasedCanary@ deployment.
timeBasedCanary_canaryPercentage :: Lens.Lens' TimeBasedCanary (Prelude.Maybe Prelude.Int)
timeBasedCanary_canaryPercentage :: (Maybe Int -> f (Maybe Int))
-> TimeBasedCanary -> f TimeBasedCanary
timeBasedCanary_canaryPercentage = (TimeBasedCanary -> Maybe Int)
-> (TimeBasedCanary -> Maybe Int -> TimeBasedCanary)
-> Lens TimeBasedCanary TimeBasedCanary (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimeBasedCanary' {Maybe Int
canaryPercentage :: Maybe Int
$sel:canaryPercentage:TimeBasedCanary' :: TimeBasedCanary -> Maybe Int
canaryPercentage} -> Maybe Int
canaryPercentage) (\s :: TimeBasedCanary
s@TimeBasedCanary' {} Maybe Int
a -> TimeBasedCanary
s {$sel:canaryPercentage:TimeBasedCanary' :: Maybe Int
canaryPercentage = Maybe Int
a} :: TimeBasedCanary)

instance Core.FromJSON TimeBasedCanary where
  parseJSON :: Value -> Parser TimeBasedCanary
parseJSON =
    String
-> (Object -> Parser TimeBasedCanary)
-> Value
-> Parser TimeBasedCanary
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TimeBasedCanary"
      ( \Object
x ->
          Maybe Int -> Maybe Int -> TimeBasedCanary
TimeBasedCanary'
            (Maybe Int -> Maybe Int -> TimeBasedCanary)
-> Parser (Maybe Int) -> Parser (Maybe Int -> TimeBasedCanary)
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
"canaryInterval")
            Parser (Maybe Int -> TimeBasedCanary)
-> Parser (Maybe Int) -> Parser TimeBasedCanary
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
"canaryPercentage")
      )

instance Prelude.Hashable TimeBasedCanary

instance Prelude.NFData TimeBasedCanary

instance Core.ToJSON TimeBasedCanary where
  toJSON :: TimeBasedCanary -> Value
toJSON TimeBasedCanary' {Maybe Int
canaryPercentage :: Maybe Int
canaryInterval :: Maybe Int
$sel:canaryPercentage:TimeBasedCanary' :: TimeBasedCanary -> Maybe Int
$sel:canaryInterval:TimeBasedCanary' :: TimeBasedCanary -> Maybe Int
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"canaryInterval" 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
canaryInterval,
            (Text
"canaryPercentage" 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
canaryPercentage
          ]
      )