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

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

-- | An object that represents the backends that a virtual node is expected
-- to send outbound traffic to.
--
-- /See:/ 'newBackend' smart constructor.
data Backend = Backend'
  { -- | Specifies a virtual service to use as a backend.
    Backend -> Maybe VirtualServiceBackend
virtualService :: Prelude.Maybe VirtualServiceBackend
  }
  deriving (Backend -> Backend -> Bool
(Backend -> Backend -> Bool)
-> (Backend -> Backend -> Bool) -> Eq Backend
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Backend -> Backend -> Bool
$c/= :: Backend -> Backend -> Bool
== :: Backend -> Backend -> Bool
$c== :: Backend -> Backend -> Bool
Prelude.Eq, ReadPrec [Backend]
ReadPrec Backend
Int -> ReadS Backend
ReadS [Backend]
(Int -> ReadS Backend)
-> ReadS [Backend]
-> ReadPrec Backend
-> ReadPrec [Backend]
-> Read Backend
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Backend]
$creadListPrec :: ReadPrec [Backend]
readPrec :: ReadPrec Backend
$creadPrec :: ReadPrec Backend
readList :: ReadS [Backend]
$creadList :: ReadS [Backend]
readsPrec :: Int -> ReadS Backend
$creadsPrec :: Int -> ReadS Backend
Prelude.Read, Int -> Backend -> ShowS
[Backend] -> ShowS
Backend -> String
(Int -> Backend -> ShowS)
-> (Backend -> String) -> ([Backend] -> ShowS) -> Show Backend
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Backend] -> ShowS
$cshowList :: [Backend] -> ShowS
show :: Backend -> String
$cshow :: Backend -> String
showsPrec :: Int -> Backend -> ShowS
$cshowsPrec :: Int -> Backend -> ShowS
Prelude.Show, (forall x. Backend -> Rep Backend x)
-> (forall x. Rep Backend x -> Backend) -> Generic Backend
forall x. Rep Backend x -> Backend
forall x. Backend -> Rep Backend x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Backend x -> Backend
$cfrom :: forall x. Backend -> Rep Backend x
Prelude.Generic)

-- |
-- Create a value of 'Backend' 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:
--
-- 'virtualService', 'backend_virtualService' - Specifies a virtual service to use as a backend.
newBackend ::
  Backend
newBackend :: Backend
newBackend =
  Backend' :: Maybe VirtualServiceBackend -> Backend
Backend' {$sel:virtualService:Backend' :: Maybe VirtualServiceBackend
virtualService = Maybe VirtualServiceBackend
forall a. Maybe a
Prelude.Nothing}

-- | Specifies a virtual service to use as a backend.
backend_virtualService :: Lens.Lens' Backend (Prelude.Maybe VirtualServiceBackend)
backend_virtualService :: (Maybe VirtualServiceBackend -> f (Maybe VirtualServiceBackend))
-> Backend -> f Backend
backend_virtualService = (Backend -> Maybe VirtualServiceBackend)
-> (Backend -> Maybe VirtualServiceBackend -> Backend)
-> Lens
     Backend
     Backend
     (Maybe VirtualServiceBackend)
     (Maybe VirtualServiceBackend)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Backend' {Maybe VirtualServiceBackend
virtualService :: Maybe VirtualServiceBackend
$sel:virtualService:Backend' :: Backend -> Maybe VirtualServiceBackend
virtualService} -> Maybe VirtualServiceBackend
virtualService) (\s :: Backend
s@Backend' {} Maybe VirtualServiceBackend
a -> Backend
s {$sel:virtualService:Backend' :: Maybe VirtualServiceBackend
virtualService = Maybe VirtualServiceBackend
a} :: Backend)

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

instance Prelude.Hashable Backend

instance Prelude.NFData Backend

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