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

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

-- | An object that represents a virtual service backend for a virtual node.
--
-- /See:/ 'newVirtualServiceBackend' smart constructor.
data VirtualServiceBackend = VirtualServiceBackend'
  { -- | A reference to an object that represents the client policy for a
    -- backend.
    VirtualServiceBackend -> Maybe ClientPolicy
clientPolicy :: Prelude.Maybe ClientPolicy,
    -- | The name of the virtual service that is acting as a virtual node
    -- backend.
    VirtualServiceBackend -> Text
virtualServiceName :: Prelude.Text
  }
  deriving (VirtualServiceBackend -> VirtualServiceBackend -> Bool
(VirtualServiceBackend -> VirtualServiceBackend -> Bool)
-> (VirtualServiceBackend -> VirtualServiceBackend -> Bool)
-> Eq VirtualServiceBackend
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VirtualServiceBackend -> VirtualServiceBackend -> Bool
$c/= :: VirtualServiceBackend -> VirtualServiceBackend -> Bool
== :: VirtualServiceBackend -> VirtualServiceBackend -> Bool
$c== :: VirtualServiceBackend -> VirtualServiceBackend -> Bool
Prelude.Eq, ReadPrec [VirtualServiceBackend]
ReadPrec VirtualServiceBackend
Int -> ReadS VirtualServiceBackend
ReadS [VirtualServiceBackend]
(Int -> ReadS VirtualServiceBackend)
-> ReadS [VirtualServiceBackend]
-> ReadPrec VirtualServiceBackend
-> ReadPrec [VirtualServiceBackend]
-> Read VirtualServiceBackend
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [VirtualServiceBackend]
$creadListPrec :: ReadPrec [VirtualServiceBackend]
readPrec :: ReadPrec VirtualServiceBackend
$creadPrec :: ReadPrec VirtualServiceBackend
readList :: ReadS [VirtualServiceBackend]
$creadList :: ReadS [VirtualServiceBackend]
readsPrec :: Int -> ReadS VirtualServiceBackend
$creadsPrec :: Int -> ReadS VirtualServiceBackend
Prelude.Read, Int -> VirtualServiceBackend -> ShowS
[VirtualServiceBackend] -> ShowS
VirtualServiceBackend -> String
(Int -> VirtualServiceBackend -> ShowS)
-> (VirtualServiceBackend -> String)
-> ([VirtualServiceBackend] -> ShowS)
-> Show VirtualServiceBackend
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VirtualServiceBackend] -> ShowS
$cshowList :: [VirtualServiceBackend] -> ShowS
show :: VirtualServiceBackend -> String
$cshow :: VirtualServiceBackend -> String
showsPrec :: Int -> VirtualServiceBackend -> ShowS
$cshowsPrec :: Int -> VirtualServiceBackend -> ShowS
Prelude.Show, (forall x. VirtualServiceBackend -> Rep VirtualServiceBackend x)
-> (forall x. Rep VirtualServiceBackend x -> VirtualServiceBackend)
-> Generic VirtualServiceBackend
forall x. Rep VirtualServiceBackend x -> VirtualServiceBackend
forall x. VirtualServiceBackend -> Rep VirtualServiceBackend x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep VirtualServiceBackend x -> VirtualServiceBackend
$cfrom :: forall x. VirtualServiceBackend -> Rep VirtualServiceBackend x
Prelude.Generic)

-- |
-- Create a value of 'VirtualServiceBackend' 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:
--
-- 'clientPolicy', 'virtualServiceBackend_clientPolicy' - A reference to an object that represents the client policy for a
-- backend.
--
-- 'virtualServiceName', 'virtualServiceBackend_virtualServiceName' - The name of the virtual service that is acting as a virtual node
-- backend.
newVirtualServiceBackend ::
  -- | 'virtualServiceName'
  Prelude.Text ->
  VirtualServiceBackend
newVirtualServiceBackend :: Text -> VirtualServiceBackend
newVirtualServiceBackend Text
pVirtualServiceName_ =
  VirtualServiceBackend' :: Maybe ClientPolicy -> Text -> VirtualServiceBackend
VirtualServiceBackend'
    { $sel:clientPolicy:VirtualServiceBackend' :: Maybe ClientPolicy
clientPolicy =
        Maybe ClientPolicy
forall a. Maybe a
Prelude.Nothing,
      $sel:virtualServiceName:VirtualServiceBackend' :: Text
virtualServiceName = Text
pVirtualServiceName_
    }

-- | A reference to an object that represents the client policy for a
-- backend.
virtualServiceBackend_clientPolicy :: Lens.Lens' VirtualServiceBackend (Prelude.Maybe ClientPolicy)
virtualServiceBackend_clientPolicy :: (Maybe ClientPolicy -> f (Maybe ClientPolicy))
-> VirtualServiceBackend -> f VirtualServiceBackend
virtualServiceBackend_clientPolicy = (VirtualServiceBackend -> Maybe ClientPolicy)
-> (VirtualServiceBackend
    -> Maybe ClientPolicy -> VirtualServiceBackend)
-> Lens
     VirtualServiceBackend
     VirtualServiceBackend
     (Maybe ClientPolicy)
     (Maybe ClientPolicy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VirtualServiceBackend' {Maybe ClientPolicy
clientPolicy :: Maybe ClientPolicy
$sel:clientPolicy:VirtualServiceBackend' :: VirtualServiceBackend -> Maybe ClientPolicy
clientPolicy} -> Maybe ClientPolicy
clientPolicy) (\s :: VirtualServiceBackend
s@VirtualServiceBackend' {} Maybe ClientPolicy
a -> VirtualServiceBackend
s {$sel:clientPolicy:VirtualServiceBackend' :: Maybe ClientPolicy
clientPolicy = Maybe ClientPolicy
a} :: VirtualServiceBackend)

-- | The name of the virtual service that is acting as a virtual node
-- backend.
virtualServiceBackend_virtualServiceName :: Lens.Lens' VirtualServiceBackend Prelude.Text
virtualServiceBackend_virtualServiceName :: (Text -> f Text)
-> VirtualServiceBackend -> f VirtualServiceBackend
virtualServiceBackend_virtualServiceName = (VirtualServiceBackend -> Text)
-> (VirtualServiceBackend -> Text -> VirtualServiceBackend)
-> Lens VirtualServiceBackend VirtualServiceBackend Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VirtualServiceBackend' {Text
virtualServiceName :: Text
$sel:virtualServiceName:VirtualServiceBackend' :: VirtualServiceBackend -> Text
virtualServiceName} -> Text
virtualServiceName) (\s :: VirtualServiceBackend
s@VirtualServiceBackend' {} Text
a -> VirtualServiceBackend
s {$sel:virtualServiceName:VirtualServiceBackend' :: Text
virtualServiceName = Text
a} :: VirtualServiceBackend)

instance Core.FromJSON VirtualServiceBackend where
  parseJSON :: Value -> Parser VirtualServiceBackend
parseJSON =
    String
-> (Object -> Parser VirtualServiceBackend)
-> Value
-> Parser VirtualServiceBackend
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"VirtualServiceBackend"
      ( \Object
x ->
          Maybe ClientPolicy -> Text -> VirtualServiceBackend
VirtualServiceBackend'
            (Maybe ClientPolicy -> Text -> VirtualServiceBackend)
-> Parser (Maybe ClientPolicy)
-> Parser (Text -> VirtualServiceBackend)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe ClientPolicy)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"clientPolicy")
            Parser (Text -> VirtualServiceBackend)
-> Parser Text -> Parser VirtualServiceBackend
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"virtualServiceName")
      )

instance Prelude.Hashable VirtualServiceBackend

instance Prelude.NFData VirtualServiceBackend

instance Core.ToJSON VirtualServiceBackend where
  toJSON :: VirtualServiceBackend -> Value
toJSON VirtualServiceBackend' {Maybe ClientPolicy
Text
virtualServiceName :: Text
clientPolicy :: Maybe ClientPolicy
$sel:virtualServiceName:VirtualServiceBackend' :: VirtualServiceBackend -> Text
$sel:clientPolicy:VirtualServiceBackend' :: VirtualServiceBackend -> Maybe ClientPolicy
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"clientPolicy" Text -> ClientPolicy -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (ClientPolicy -> Pair) -> Maybe ClientPolicy -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ClientPolicy
clientPolicy,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"virtualServiceName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
virtualServiceName)
          ]
      )