{-# 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.ELBV2.Types.ForwardActionConfig
-- 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.ELBV2.Types.ForwardActionConfig where

import qualified Amazonka.Core as Core
import Amazonka.ELBV2.Types.TargetGroupStickinessConfig
import Amazonka.ELBV2.Types.TargetGroupTuple
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information about a forward action.
--
-- /See:/ 'newForwardActionConfig' smart constructor.
data ForwardActionConfig = ForwardActionConfig'
  { -- | One or more target groups. For Network Load Balancers, you can specify a
    -- single target group.
    ForwardActionConfig -> Maybe [TargetGroupTuple]
targetGroups :: Prelude.Maybe [TargetGroupTuple],
    -- | The target group stickiness for the rule.
    ForwardActionConfig -> Maybe TargetGroupStickinessConfig
targetGroupStickinessConfig :: Prelude.Maybe TargetGroupStickinessConfig
  }
  deriving (ForwardActionConfig -> ForwardActionConfig -> Bool
(ForwardActionConfig -> ForwardActionConfig -> Bool)
-> (ForwardActionConfig -> ForwardActionConfig -> Bool)
-> Eq ForwardActionConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ForwardActionConfig -> ForwardActionConfig -> Bool
$c/= :: ForwardActionConfig -> ForwardActionConfig -> Bool
== :: ForwardActionConfig -> ForwardActionConfig -> Bool
$c== :: ForwardActionConfig -> ForwardActionConfig -> Bool
Prelude.Eq, ReadPrec [ForwardActionConfig]
ReadPrec ForwardActionConfig
Int -> ReadS ForwardActionConfig
ReadS [ForwardActionConfig]
(Int -> ReadS ForwardActionConfig)
-> ReadS [ForwardActionConfig]
-> ReadPrec ForwardActionConfig
-> ReadPrec [ForwardActionConfig]
-> Read ForwardActionConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ForwardActionConfig]
$creadListPrec :: ReadPrec [ForwardActionConfig]
readPrec :: ReadPrec ForwardActionConfig
$creadPrec :: ReadPrec ForwardActionConfig
readList :: ReadS [ForwardActionConfig]
$creadList :: ReadS [ForwardActionConfig]
readsPrec :: Int -> ReadS ForwardActionConfig
$creadsPrec :: Int -> ReadS ForwardActionConfig
Prelude.Read, Int -> ForwardActionConfig -> ShowS
[ForwardActionConfig] -> ShowS
ForwardActionConfig -> String
(Int -> ForwardActionConfig -> ShowS)
-> (ForwardActionConfig -> String)
-> ([ForwardActionConfig] -> ShowS)
-> Show ForwardActionConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ForwardActionConfig] -> ShowS
$cshowList :: [ForwardActionConfig] -> ShowS
show :: ForwardActionConfig -> String
$cshow :: ForwardActionConfig -> String
showsPrec :: Int -> ForwardActionConfig -> ShowS
$cshowsPrec :: Int -> ForwardActionConfig -> ShowS
Prelude.Show, (forall x. ForwardActionConfig -> Rep ForwardActionConfig x)
-> (forall x. Rep ForwardActionConfig x -> ForwardActionConfig)
-> Generic ForwardActionConfig
forall x. Rep ForwardActionConfig x -> ForwardActionConfig
forall x. ForwardActionConfig -> Rep ForwardActionConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ForwardActionConfig x -> ForwardActionConfig
$cfrom :: forall x. ForwardActionConfig -> Rep ForwardActionConfig x
Prelude.Generic)

-- |
-- Create a value of 'ForwardActionConfig' 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:
--
-- 'targetGroups', 'forwardActionConfig_targetGroups' - One or more target groups. For Network Load Balancers, you can specify a
-- single target group.
--
-- 'targetGroupStickinessConfig', 'forwardActionConfig_targetGroupStickinessConfig' - The target group stickiness for the rule.
newForwardActionConfig ::
  ForwardActionConfig
newForwardActionConfig :: ForwardActionConfig
newForwardActionConfig =
  ForwardActionConfig' :: Maybe [TargetGroupTuple]
-> Maybe TargetGroupStickinessConfig -> ForwardActionConfig
ForwardActionConfig'
    { $sel:targetGroups:ForwardActionConfig' :: Maybe [TargetGroupTuple]
targetGroups =
        Maybe [TargetGroupTuple]
forall a. Maybe a
Prelude.Nothing,
      $sel:targetGroupStickinessConfig:ForwardActionConfig' :: Maybe TargetGroupStickinessConfig
targetGroupStickinessConfig = Maybe TargetGroupStickinessConfig
forall a. Maybe a
Prelude.Nothing
    }

-- | One or more target groups. For Network Load Balancers, you can specify a
-- single target group.
forwardActionConfig_targetGroups :: Lens.Lens' ForwardActionConfig (Prelude.Maybe [TargetGroupTuple])
forwardActionConfig_targetGroups :: (Maybe [TargetGroupTuple] -> f (Maybe [TargetGroupTuple]))
-> ForwardActionConfig -> f ForwardActionConfig
forwardActionConfig_targetGroups = (ForwardActionConfig -> Maybe [TargetGroupTuple])
-> (ForwardActionConfig
    -> Maybe [TargetGroupTuple] -> ForwardActionConfig)
-> Lens
     ForwardActionConfig
     ForwardActionConfig
     (Maybe [TargetGroupTuple])
     (Maybe [TargetGroupTuple])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ForwardActionConfig' {Maybe [TargetGroupTuple]
targetGroups :: Maybe [TargetGroupTuple]
$sel:targetGroups:ForwardActionConfig' :: ForwardActionConfig -> Maybe [TargetGroupTuple]
targetGroups} -> Maybe [TargetGroupTuple]
targetGroups) (\s :: ForwardActionConfig
s@ForwardActionConfig' {} Maybe [TargetGroupTuple]
a -> ForwardActionConfig
s {$sel:targetGroups:ForwardActionConfig' :: Maybe [TargetGroupTuple]
targetGroups = Maybe [TargetGroupTuple]
a} :: ForwardActionConfig) ((Maybe [TargetGroupTuple] -> f (Maybe [TargetGroupTuple]))
 -> ForwardActionConfig -> f ForwardActionConfig)
-> ((Maybe [TargetGroupTuple] -> f (Maybe [TargetGroupTuple]))
    -> Maybe [TargetGroupTuple] -> f (Maybe [TargetGroupTuple]))
-> (Maybe [TargetGroupTuple] -> f (Maybe [TargetGroupTuple]))
-> ForwardActionConfig
-> f ForwardActionConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [TargetGroupTuple]
  [TargetGroupTuple]
  [TargetGroupTuple]
  [TargetGroupTuple]
-> Iso
     (Maybe [TargetGroupTuple])
     (Maybe [TargetGroupTuple])
     (Maybe [TargetGroupTuple])
     (Maybe [TargetGroupTuple])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [TargetGroupTuple]
  [TargetGroupTuple]
  [TargetGroupTuple]
  [TargetGroupTuple]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The target group stickiness for the rule.
forwardActionConfig_targetGroupStickinessConfig :: Lens.Lens' ForwardActionConfig (Prelude.Maybe TargetGroupStickinessConfig)
forwardActionConfig_targetGroupStickinessConfig :: (Maybe TargetGroupStickinessConfig
 -> f (Maybe TargetGroupStickinessConfig))
-> ForwardActionConfig -> f ForwardActionConfig
forwardActionConfig_targetGroupStickinessConfig = (ForwardActionConfig -> Maybe TargetGroupStickinessConfig)
-> (ForwardActionConfig
    -> Maybe TargetGroupStickinessConfig -> ForwardActionConfig)
-> Lens
     ForwardActionConfig
     ForwardActionConfig
     (Maybe TargetGroupStickinessConfig)
     (Maybe TargetGroupStickinessConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ForwardActionConfig' {Maybe TargetGroupStickinessConfig
targetGroupStickinessConfig :: Maybe TargetGroupStickinessConfig
$sel:targetGroupStickinessConfig:ForwardActionConfig' :: ForwardActionConfig -> Maybe TargetGroupStickinessConfig
targetGroupStickinessConfig} -> Maybe TargetGroupStickinessConfig
targetGroupStickinessConfig) (\s :: ForwardActionConfig
s@ForwardActionConfig' {} Maybe TargetGroupStickinessConfig
a -> ForwardActionConfig
s {$sel:targetGroupStickinessConfig:ForwardActionConfig' :: Maybe TargetGroupStickinessConfig
targetGroupStickinessConfig = Maybe TargetGroupStickinessConfig
a} :: ForwardActionConfig)

instance Core.FromXML ForwardActionConfig where
  parseXML :: [Node] -> Either String ForwardActionConfig
parseXML [Node]
x =
    Maybe [TargetGroupTuple]
-> Maybe TargetGroupStickinessConfig -> ForwardActionConfig
ForwardActionConfig'
      (Maybe [TargetGroupTuple]
 -> Maybe TargetGroupStickinessConfig -> ForwardActionConfig)
-> Either String (Maybe [TargetGroupTuple])
-> Either
     String (Maybe TargetGroupStickinessConfig -> ForwardActionConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"TargetGroups" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String (Maybe [TargetGroupTuple]))
-> Either String (Maybe [TargetGroupTuple])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [TargetGroupTuple])
-> [Node] -> Either String (Maybe [TargetGroupTuple])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [TargetGroupTuple]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member")
                  )
      Either
  String (Maybe TargetGroupStickinessConfig -> ForwardActionConfig)
-> Either String (Maybe TargetGroupStickinessConfig)
-> Either String ForwardActionConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe TargetGroupStickinessConfig)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"TargetGroupStickinessConfig")

instance Prelude.Hashable ForwardActionConfig

instance Prelude.NFData ForwardActionConfig

instance Core.ToQuery ForwardActionConfig where
  toQuery :: ForwardActionConfig -> QueryString
toQuery ForwardActionConfig' {Maybe [TargetGroupTuple]
Maybe TargetGroupStickinessConfig
targetGroupStickinessConfig :: Maybe TargetGroupStickinessConfig
targetGroups :: Maybe [TargetGroupTuple]
$sel:targetGroupStickinessConfig:ForwardActionConfig' :: ForwardActionConfig -> Maybe TargetGroupStickinessConfig
$sel:targetGroups:ForwardActionConfig' :: ForwardActionConfig -> Maybe [TargetGroupTuple]
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"TargetGroups"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            (ByteString -> [TargetGroupTuple] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member" ([TargetGroupTuple] -> QueryString)
-> Maybe [TargetGroupTuple] -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [TargetGroupTuple]
targetGroups),
        ByteString
"TargetGroupStickinessConfig"
          ByteString -> Maybe TargetGroupStickinessConfig -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe TargetGroupStickinessConfig
targetGroupStickinessConfig
      ]