{-# 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.AppMesh.Types.TcpRouteAction
-- 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.AppMesh.Types.TcpRouteAction where

import Amazonka.AppMesh.Types.WeightedTarget
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that represents the action to take if a match is determined.
--
-- /See:/ 'newTcpRouteAction' smart constructor.
data TcpRouteAction = TcpRouteAction'
  { -- | An object that represents the targets that traffic is routed to when a
    -- request matches the route.
    TcpRouteAction -> NonEmpty WeightedTarget
weightedTargets :: Prelude.NonEmpty WeightedTarget
  }
  deriving (TcpRouteAction -> TcpRouteAction -> Bool
(TcpRouteAction -> TcpRouteAction -> Bool)
-> (TcpRouteAction -> TcpRouteAction -> Bool) -> Eq TcpRouteAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TcpRouteAction -> TcpRouteAction -> Bool
$c/= :: TcpRouteAction -> TcpRouteAction -> Bool
== :: TcpRouteAction -> TcpRouteAction -> Bool
$c== :: TcpRouteAction -> TcpRouteAction -> Bool
Prelude.Eq, ReadPrec [TcpRouteAction]
ReadPrec TcpRouteAction
Int -> ReadS TcpRouteAction
ReadS [TcpRouteAction]
(Int -> ReadS TcpRouteAction)
-> ReadS [TcpRouteAction]
-> ReadPrec TcpRouteAction
-> ReadPrec [TcpRouteAction]
-> Read TcpRouteAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TcpRouteAction]
$creadListPrec :: ReadPrec [TcpRouteAction]
readPrec :: ReadPrec TcpRouteAction
$creadPrec :: ReadPrec TcpRouteAction
readList :: ReadS [TcpRouteAction]
$creadList :: ReadS [TcpRouteAction]
readsPrec :: Int -> ReadS TcpRouteAction
$creadsPrec :: Int -> ReadS TcpRouteAction
Prelude.Read, Int -> TcpRouteAction -> ShowS
[TcpRouteAction] -> ShowS
TcpRouteAction -> String
(Int -> TcpRouteAction -> ShowS)
-> (TcpRouteAction -> String)
-> ([TcpRouteAction] -> ShowS)
-> Show TcpRouteAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TcpRouteAction] -> ShowS
$cshowList :: [TcpRouteAction] -> ShowS
show :: TcpRouteAction -> String
$cshow :: TcpRouteAction -> String
showsPrec :: Int -> TcpRouteAction -> ShowS
$cshowsPrec :: Int -> TcpRouteAction -> ShowS
Prelude.Show, (forall x. TcpRouteAction -> Rep TcpRouteAction x)
-> (forall x. Rep TcpRouteAction x -> TcpRouteAction)
-> Generic TcpRouteAction
forall x. Rep TcpRouteAction x -> TcpRouteAction
forall x. TcpRouteAction -> Rep TcpRouteAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TcpRouteAction x -> TcpRouteAction
$cfrom :: forall x. TcpRouteAction -> Rep TcpRouteAction x
Prelude.Generic)

-- |
-- Create a value of 'TcpRouteAction' 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:
--
-- 'weightedTargets', 'tcpRouteAction_weightedTargets' - An object that represents the targets that traffic is routed to when a
-- request matches the route.
newTcpRouteAction ::
  -- | 'weightedTargets'
  Prelude.NonEmpty WeightedTarget ->
  TcpRouteAction
newTcpRouteAction :: NonEmpty WeightedTarget -> TcpRouteAction
newTcpRouteAction NonEmpty WeightedTarget
pWeightedTargets_ =
  TcpRouteAction' :: NonEmpty WeightedTarget -> TcpRouteAction
TcpRouteAction'
    { $sel:weightedTargets:TcpRouteAction' :: NonEmpty WeightedTarget
weightedTargets =
        Tagged
  (NonEmpty WeightedTarget) (Identity (NonEmpty WeightedTarget))
-> Tagged
     (NonEmpty WeightedTarget) (Identity (NonEmpty WeightedTarget))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged
   (NonEmpty WeightedTarget) (Identity (NonEmpty WeightedTarget))
 -> Tagged
      (NonEmpty WeightedTarget) (Identity (NonEmpty WeightedTarget)))
-> NonEmpty WeightedTarget -> NonEmpty WeightedTarget
forall t b. AReview t b -> b -> t
Lens.# NonEmpty WeightedTarget
pWeightedTargets_
    }

-- | An object that represents the targets that traffic is routed to when a
-- request matches the route.
tcpRouteAction_weightedTargets :: Lens.Lens' TcpRouteAction (Prelude.NonEmpty WeightedTarget)
tcpRouteAction_weightedTargets :: (NonEmpty WeightedTarget -> f (NonEmpty WeightedTarget))
-> TcpRouteAction -> f TcpRouteAction
tcpRouteAction_weightedTargets = (TcpRouteAction -> NonEmpty WeightedTarget)
-> (TcpRouteAction -> NonEmpty WeightedTarget -> TcpRouteAction)
-> Lens
     TcpRouteAction
     TcpRouteAction
     (NonEmpty WeightedTarget)
     (NonEmpty WeightedTarget)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TcpRouteAction' {NonEmpty WeightedTarget
weightedTargets :: NonEmpty WeightedTarget
$sel:weightedTargets:TcpRouteAction' :: TcpRouteAction -> NonEmpty WeightedTarget
weightedTargets} -> NonEmpty WeightedTarget
weightedTargets) (\s :: TcpRouteAction
s@TcpRouteAction' {} NonEmpty WeightedTarget
a -> TcpRouteAction
s {$sel:weightedTargets:TcpRouteAction' :: NonEmpty WeightedTarget
weightedTargets = NonEmpty WeightedTarget
a} :: TcpRouteAction) ((NonEmpty WeightedTarget -> f (NonEmpty WeightedTarget))
 -> TcpRouteAction -> f TcpRouteAction)
-> ((NonEmpty WeightedTarget -> f (NonEmpty WeightedTarget))
    -> NonEmpty WeightedTarget -> f (NonEmpty WeightedTarget))
-> (NonEmpty WeightedTarget -> f (NonEmpty WeightedTarget))
-> TcpRouteAction
-> f TcpRouteAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty WeightedTarget -> f (NonEmpty WeightedTarget))
-> NonEmpty WeightedTarget -> f (NonEmpty WeightedTarget)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON TcpRouteAction where
  parseJSON :: Value -> Parser TcpRouteAction
parseJSON =
    String
-> (Object -> Parser TcpRouteAction)
-> Value
-> Parser TcpRouteAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TcpRouteAction"
      ( \Object
x ->
          NonEmpty WeightedTarget -> TcpRouteAction
TcpRouteAction'
            (NonEmpty WeightedTarget -> TcpRouteAction)
-> Parser (NonEmpty WeightedTarget) -> Parser TcpRouteAction
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (NonEmpty WeightedTarget)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"weightedTargets")
      )

instance Prelude.Hashable TcpRouteAction

instance Prelude.NFData TcpRouteAction

instance Core.ToJSON TcpRouteAction where
  toJSON :: TcpRouteAction -> Value
toJSON TcpRouteAction' {NonEmpty WeightedTarget
weightedTargets :: NonEmpty WeightedTarget
$sel:weightedTargets:TcpRouteAction' :: TcpRouteAction -> NonEmpty WeightedTarget
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"weightedTargets" Text -> NonEmpty WeightedTarget -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty WeightedTarget
weightedTargets)
          ]
      )