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

import Amazonka.CodeDeploy.Types.TimeBasedCanary
import Amazonka.CodeDeploy.Types.TimeBasedLinear
import Amazonka.CodeDeploy.Types.TrafficRoutingType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The configuration that specifies how traffic is shifted from one version
-- of a Lambda function to another version during an AWS Lambda deployment,
-- or from one Amazon ECS task set to another during an Amazon ECS
-- deployment.
--
-- /See:/ 'newTrafficRoutingConfig' smart constructor.
data TrafficRoutingConfig = TrafficRoutingConfig'
  { -- | 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.
    TrafficRoutingConfig -> Maybe TimeBasedCanary
timeBasedCanary :: Prelude.Maybe TimeBasedCanary,
    -- | 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.
    TrafficRoutingConfig -> Maybe TimeBasedLinear
timeBasedLinear :: Prelude.Maybe TimeBasedLinear,
    -- | The type of traffic shifting (@TimeBasedCanary@ or @TimeBasedLinear@)
    -- used by a deployment configuration.
    TrafficRoutingConfig -> Maybe TrafficRoutingType
type' :: Prelude.Maybe TrafficRoutingType
  }
  deriving (TrafficRoutingConfig -> TrafficRoutingConfig -> Bool
(TrafficRoutingConfig -> TrafficRoutingConfig -> Bool)
-> (TrafficRoutingConfig -> TrafficRoutingConfig -> Bool)
-> Eq TrafficRoutingConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TrafficRoutingConfig -> TrafficRoutingConfig -> Bool
$c/= :: TrafficRoutingConfig -> TrafficRoutingConfig -> Bool
== :: TrafficRoutingConfig -> TrafficRoutingConfig -> Bool
$c== :: TrafficRoutingConfig -> TrafficRoutingConfig -> Bool
Prelude.Eq, ReadPrec [TrafficRoutingConfig]
ReadPrec TrafficRoutingConfig
Int -> ReadS TrafficRoutingConfig
ReadS [TrafficRoutingConfig]
(Int -> ReadS TrafficRoutingConfig)
-> ReadS [TrafficRoutingConfig]
-> ReadPrec TrafficRoutingConfig
-> ReadPrec [TrafficRoutingConfig]
-> Read TrafficRoutingConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TrafficRoutingConfig]
$creadListPrec :: ReadPrec [TrafficRoutingConfig]
readPrec :: ReadPrec TrafficRoutingConfig
$creadPrec :: ReadPrec TrafficRoutingConfig
readList :: ReadS [TrafficRoutingConfig]
$creadList :: ReadS [TrafficRoutingConfig]
readsPrec :: Int -> ReadS TrafficRoutingConfig
$creadsPrec :: Int -> ReadS TrafficRoutingConfig
Prelude.Read, Int -> TrafficRoutingConfig -> ShowS
[TrafficRoutingConfig] -> ShowS
TrafficRoutingConfig -> String
(Int -> TrafficRoutingConfig -> ShowS)
-> (TrafficRoutingConfig -> String)
-> ([TrafficRoutingConfig] -> ShowS)
-> Show TrafficRoutingConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TrafficRoutingConfig] -> ShowS
$cshowList :: [TrafficRoutingConfig] -> ShowS
show :: TrafficRoutingConfig -> String
$cshow :: TrafficRoutingConfig -> String
showsPrec :: Int -> TrafficRoutingConfig -> ShowS
$cshowsPrec :: Int -> TrafficRoutingConfig -> ShowS
Prelude.Show, (forall x. TrafficRoutingConfig -> Rep TrafficRoutingConfig x)
-> (forall x. Rep TrafficRoutingConfig x -> TrafficRoutingConfig)
-> Generic TrafficRoutingConfig
forall x. Rep TrafficRoutingConfig x -> TrafficRoutingConfig
forall x. TrafficRoutingConfig -> Rep TrafficRoutingConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TrafficRoutingConfig x -> TrafficRoutingConfig
$cfrom :: forall x. TrafficRoutingConfig -> Rep TrafficRoutingConfig x
Prelude.Generic)

-- |
-- Create a value of 'TrafficRoutingConfig' 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:
--
-- 'timeBasedCanary', 'trafficRoutingConfig_timeBasedCanary' - 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.
--
-- 'timeBasedLinear', 'trafficRoutingConfig_timeBasedLinear' - 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.
--
-- 'type'', 'trafficRoutingConfig_type' - The type of traffic shifting (@TimeBasedCanary@ or @TimeBasedLinear@)
-- used by a deployment configuration.
newTrafficRoutingConfig ::
  TrafficRoutingConfig
newTrafficRoutingConfig :: TrafficRoutingConfig
newTrafficRoutingConfig =
  TrafficRoutingConfig' :: Maybe TimeBasedCanary
-> Maybe TimeBasedLinear
-> Maybe TrafficRoutingType
-> TrafficRoutingConfig
TrafficRoutingConfig'
    { $sel:timeBasedCanary:TrafficRoutingConfig' :: Maybe TimeBasedCanary
timeBasedCanary =
        Maybe TimeBasedCanary
forall a. Maybe a
Prelude.Nothing,
      $sel:timeBasedLinear:TrafficRoutingConfig' :: Maybe TimeBasedLinear
timeBasedLinear = Maybe TimeBasedLinear
forall a. Maybe a
Prelude.Nothing,
      $sel:type':TrafficRoutingConfig' :: Maybe TrafficRoutingType
type' = Maybe TrafficRoutingType
forall a. Maybe a
Prelude.Nothing
    }

-- | 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.
trafficRoutingConfig_timeBasedCanary :: Lens.Lens' TrafficRoutingConfig (Prelude.Maybe TimeBasedCanary)
trafficRoutingConfig_timeBasedCanary :: (Maybe TimeBasedCanary -> f (Maybe TimeBasedCanary))
-> TrafficRoutingConfig -> f TrafficRoutingConfig
trafficRoutingConfig_timeBasedCanary = (TrafficRoutingConfig -> Maybe TimeBasedCanary)
-> (TrafficRoutingConfig
    -> Maybe TimeBasedCanary -> TrafficRoutingConfig)
-> Lens
     TrafficRoutingConfig
     TrafficRoutingConfig
     (Maybe TimeBasedCanary)
     (Maybe TimeBasedCanary)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TrafficRoutingConfig' {Maybe TimeBasedCanary
timeBasedCanary :: Maybe TimeBasedCanary
$sel:timeBasedCanary:TrafficRoutingConfig' :: TrafficRoutingConfig -> Maybe TimeBasedCanary
timeBasedCanary} -> Maybe TimeBasedCanary
timeBasedCanary) (\s :: TrafficRoutingConfig
s@TrafficRoutingConfig' {} Maybe TimeBasedCanary
a -> TrafficRoutingConfig
s {$sel:timeBasedCanary:TrafficRoutingConfig' :: Maybe TimeBasedCanary
timeBasedCanary = Maybe TimeBasedCanary
a} :: TrafficRoutingConfig)

-- | 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.
trafficRoutingConfig_timeBasedLinear :: Lens.Lens' TrafficRoutingConfig (Prelude.Maybe TimeBasedLinear)
trafficRoutingConfig_timeBasedLinear :: (Maybe TimeBasedLinear -> f (Maybe TimeBasedLinear))
-> TrafficRoutingConfig -> f TrafficRoutingConfig
trafficRoutingConfig_timeBasedLinear = (TrafficRoutingConfig -> Maybe TimeBasedLinear)
-> (TrafficRoutingConfig
    -> Maybe TimeBasedLinear -> TrafficRoutingConfig)
-> Lens
     TrafficRoutingConfig
     TrafficRoutingConfig
     (Maybe TimeBasedLinear)
     (Maybe TimeBasedLinear)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TrafficRoutingConfig' {Maybe TimeBasedLinear
timeBasedLinear :: Maybe TimeBasedLinear
$sel:timeBasedLinear:TrafficRoutingConfig' :: TrafficRoutingConfig -> Maybe TimeBasedLinear
timeBasedLinear} -> Maybe TimeBasedLinear
timeBasedLinear) (\s :: TrafficRoutingConfig
s@TrafficRoutingConfig' {} Maybe TimeBasedLinear
a -> TrafficRoutingConfig
s {$sel:timeBasedLinear:TrafficRoutingConfig' :: Maybe TimeBasedLinear
timeBasedLinear = Maybe TimeBasedLinear
a} :: TrafficRoutingConfig)

-- | The type of traffic shifting (@TimeBasedCanary@ or @TimeBasedLinear@)
-- used by a deployment configuration.
trafficRoutingConfig_type :: Lens.Lens' TrafficRoutingConfig (Prelude.Maybe TrafficRoutingType)
trafficRoutingConfig_type :: (Maybe TrafficRoutingType -> f (Maybe TrafficRoutingType))
-> TrafficRoutingConfig -> f TrafficRoutingConfig
trafficRoutingConfig_type = (TrafficRoutingConfig -> Maybe TrafficRoutingType)
-> (TrafficRoutingConfig
    -> Maybe TrafficRoutingType -> TrafficRoutingConfig)
-> Lens
     TrafficRoutingConfig
     TrafficRoutingConfig
     (Maybe TrafficRoutingType)
     (Maybe TrafficRoutingType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TrafficRoutingConfig' {Maybe TrafficRoutingType
type' :: Maybe TrafficRoutingType
$sel:type':TrafficRoutingConfig' :: TrafficRoutingConfig -> Maybe TrafficRoutingType
type'} -> Maybe TrafficRoutingType
type') (\s :: TrafficRoutingConfig
s@TrafficRoutingConfig' {} Maybe TrafficRoutingType
a -> TrafficRoutingConfig
s {$sel:type':TrafficRoutingConfig' :: Maybe TrafficRoutingType
type' = Maybe TrafficRoutingType
a} :: TrafficRoutingConfig)

instance Core.FromJSON TrafficRoutingConfig where
  parseJSON :: Value -> Parser TrafficRoutingConfig
parseJSON =
    String
-> (Object -> Parser TrafficRoutingConfig)
-> Value
-> Parser TrafficRoutingConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TrafficRoutingConfig"
      ( \Object
x ->
          Maybe TimeBasedCanary
-> Maybe TimeBasedLinear
-> Maybe TrafficRoutingType
-> TrafficRoutingConfig
TrafficRoutingConfig'
            (Maybe TimeBasedCanary
 -> Maybe TimeBasedLinear
 -> Maybe TrafficRoutingType
 -> TrafficRoutingConfig)
-> Parser (Maybe TimeBasedCanary)
-> Parser
     (Maybe TimeBasedLinear
      -> Maybe TrafficRoutingType -> TrafficRoutingConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe TimeBasedCanary)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"timeBasedCanary")
            Parser
  (Maybe TimeBasedLinear
   -> Maybe TrafficRoutingType -> TrafficRoutingConfig)
-> Parser (Maybe TimeBasedLinear)
-> Parser (Maybe TrafficRoutingType -> TrafficRoutingConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe TimeBasedLinear)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"timeBasedLinear")
            Parser (Maybe TrafficRoutingType -> TrafficRoutingConfig)
-> Parser (Maybe TrafficRoutingType) -> Parser TrafficRoutingConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe TrafficRoutingType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"type")
      )

instance Prelude.Hashable TrafficRoutingConfig

instance Prelude.NFData TrafficRoutingConfig

instance Core.ToJSON TrafficRoutingConfig where
  toJSON :: TrafficRoutingConfig -> Value
toJSON TrafficRoutingConfig' {Maybe TimeBasedCanary
Maybe TimeBasedLinear
Maybe TrafficRoutingType
type' :: Maybe TrafficRoutingType
timeBasedLinear :: Maybe TimeBasedLinear
timeBasedCanary :: Maybe TimeBasedCanary
$sel:type':TrafficRoutingConfig' :: TrafficRoutingConfig -> Maybe TrafficRoutingType
$sel:timeBasedLinear:TrafficRoutingConfig' :: TrafficRoutingConfig -> Maybe TimeBasedLinear
$sel:timeBasedCanary:TrafficRoutingConfig' :: TrafficRoutingConfig -> Maybe TimeBasedCanary
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"timeBasedCanary" Text -> TimeBasedCanary -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (TimeBasedCanary -> Pair) -> Maybe TimeBasedCanary -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TimeBasedCanary
timeBasedCanary,
            (Text
"timeBasedLinear" Text -> TimeBasedLinear -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (TimeBasedLinear -> Pair) -> Maybe TimeBasedLinear -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TimeBasedLinear
timeBasedLinear,
            (Text
"type" Text -> TrafficRoutingType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (TrafficRoutingType -> Pair)
-> Maybe TrafficRoutingType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TrafficRoutingType
type'
          ]
      )