{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $sel:weightedTargets:TcpRouteAction' :: NonEmpty WeightedTarget
weightedTargets =
        forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced 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 :: Lens' TcpRouteAction (NonEmpty WeightedTarget)
tcpRouteAction_weightedTargets = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable TcpRouteAction where
  hashWithSalt :: Int -> TcpRouteAction -> Int
hashWithSalt Int
_salt TcpRouteAction' {NonEmpty WeightedTarget
weightedTargets :: NonEmpty WeightedTarget
$sel:weightedTargets:TcpRouteAction' :: TcpRouteAction -> NonEmpty WeightedTarget
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty WeightedTarget
weightedTargets

instance Prelude.NFData TcpRouteAction where
  rnf :: TcpRouteAction -> ()
rnf TcpRouteAction' {NonEmpty WeightedTarget
weightedTargets :: NonEmpty WeightedTarget
$sel:weightedTargets:TcpRouteAction' :: TcpRouteAction -> NonEmpty WeightedTarget
..} = forall a. NFData a => a -> ()
Prelude.rnf NonEmpty WeightedTarget
weightedTargets

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