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

import Amazonka.AppMesh.Types.VirtualServiceBackend
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 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
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]
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
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. 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' {$sel:virtualService:Backend' :: Maybe VirtualServiceBackend
virtualService = 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 :: Lens' Backend (Maybe VirtualServiceBackend)
backend_virtualService = 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 Data.FromJSON Backend where
  parseJSON :: Value -> Parser Backend
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Backend"
      ( \Object
x ->
          Maybe VirtualServiceBackend -> Backend
Backend' forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"virtualService")
      )

instance Prelude.Hashable Backend where
  hashWithSalt :: Int -> Backend -> Int
hashWithSalt Int
_salt Backend' {Maybe VirtualServiceBackend
virtualService :: Maybe VirtualServiceBackend
$sel:virtualService:Backend' :: Backend -> Maybe VirtualServiceBackend
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe VirtualServiceBackend
virtualService

instance Prelude.NFData Backend where
  rnf :: Backend -> ()
rnf Backend' {Maybe VirtualServiceBackend
virtualService :: Maybe VirtualServiceBackend
$sel:virtualService:Backend' :: Backend -> Maybe VirtualServiceBackend
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe VirtualServiceBackend
virtualService

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