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

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

-- | An object that represents the specification of a virtual router.
--
-- /See:/ 'newVirtualRouterSpec' smart constructor.
data VirtualRouterSpec = VirtualRouterSpec'
  { -- | The listeners that the virtual router is expected to receive inbound
    -- traffic from. You can specify one listener.
    VirtualRouterSpec -> Maybe (NonEmpty VirtualRouterListener)
listeners :: Prelude.Maybe (Prelude.NonEmpty VirtualRouterListener)
  }
  deriving (VirtualRouterSpec -> VirtualRouterSpec -> Bool
(VirtualRouterSpec -> VirtualRouterSpec -> Bool)
-> (VirtualRouterSpec -> VirtualRouterSpec -> Bool)
-> Eq VirtualRouterSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VirtualRouterSpec -> VirtualRouterSpec -> Bool
$c/= :: VirtualRouterSpec -> VirtualRouterSpec -> Bool
== :: VirtualRouterSpec -> VirtualRouterSpec -> Bool
$c== :: VirtualRouterSpec -> VirtualRouterSpec -> Bool
Prelude.Eq, ReadPrec [VirtualRouterSpec]
ReadPrec VirtualRouterSpec
Int -> ReadS VirtualRouterSpec
ReadS [VirtualRouterSpec]
(Int -> ReadS VirtualRouterSpec)
-> ReadS [VirtualRouterSpec]
-> ReadPrec VirtualRouterSpec
-> ReadPrec [VirtualRouterSpec]
-> Read VirtualRouterSpec
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [VirtualRouterSpec]
$creadListPrec :: ReadPrec [VirtualRouterSpec]
readPrec :: ReadPrec VirtualRouterSpec
$creadPrec :: ReadPrec VirtualRouterSpec
readList :: ReadS [VirtualRouterSpec]
$creadList :: ReadS [VirtualRouterSpec]
readsPrec :: Int -> ReadS VirtualRouterSpec
$creadsPrec :: Int -> ReadS VirtualRouterSpec
Prelude.Read, Int -> VirtualRouterSpec -> ShowS
[VirtualRouterSpec] -> ShowS
VirtualRouterSpec -> String
(Int -> VirtualRouterSpec -> ShowS)
-> (VirtualRouterSpec -> String)
-> ([VirtualRouterSpec] -> ShowS)
-> Show VirtualRouterSpec
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VirtualRouterSpec] -> ShowS
$cshowList :: [VirtualRouterSpec] -> ShowS
show :: VirtualRouterSpec -> String
$cshow :: VirtualRouterSpec -> String
showsPrec :: Int -> VirtualRouterSpec -> ShowS
$cshowsPrec :: Int -> VirtualRouterSpec -> ShowS
Prelude.Show, (forall x. VirtualRouterSpec -> Rep VirtualRouterSpec x)
-> (forall x. Rep VirtualRouterSpec x -> VirtualRouterSpec)
-> Generic VirtualRouterSpec
forall x. Rep VirtualRouterSpec x -> VirtualRouterSpec
forall x. VirtualRouterSpec -> Rep VirtualRouterSpec x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep VirtualRouterSpec x -> VirtualRouterSpec
$cfrom :: forall x. VirtualRouterSpec -> Rep VirtualRouterSpec x
Prelude.Generic)

-- |
-- Create a value of 'VirtualRouterSpec' 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:
--
-- 'listeners', 'virtualRouterSpec_listeners' - The listeners that the virtual router is expected to receive inbound
-- traffic from. You can specify one listener.
newVirtualRouterSpec ::
  VirtualRouterSpec
newVirtualRouterSpec :: VirtualRouterSpec
newVirtualRouterSpec =
  VirtualRouterSpec' :: Maybe (NonEmpty VirtualRouterListener) -> VirtualRouterSpec
VirtualRouterSpec' {$sel:listeners:VirtualRouterSpec' :: Maybe (NonEmpty VirtualRouterListener)
listeners = Maybe (NonEmpty VirtualRouterListener)
forall a. Maybe a
Prelude.Nothing}

-- | The listeners that the virtual router is expected to receive inbound
-- traffic from. You can specify one listener.
virtualRouterSpec_listeners :: Lens.Lens' VirtualRouterSpec (Prelude.Maybe (Prelude.NonEmpty VirtualRouterListener))
virtualRouterSpec_listeners :: (Maybe (NonEmpty VirtualRouterListener)
 -> f (Maybe (NonEmpty VirtualRouterListener)))
-> VirtualRouterSpec -> f VirtualRouterSpec
virtualRouterSpec_listeners = (VirtualRouterSpec -> Maybe (NonEmpty VirtualRouterListener))
-> (VirtualRouterSpec
    -> Maybe (NonEmpty VirtualRouterListener) -> VirtualRouterSpec)
-> Lens
     VirtualRouterSpec
     VirtualRouterSpec
     (Maybe (NonEmpty VirtualRouterListener))
     (Maybe (NonEmpty VirtualRouterListener))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VirtualRouterSpec' {Maybe (NonEmpty VirtualRouterListener)
listeners :: Maybe (NonEmpty VirtualRouterListener)
$sel:listeners:VirtualRouterSpec' :: VirtualRouterSpec -> Maybe (NonEmpty VirtualRouterListener)
listeners} -> Maybe (NonEmpty VirtualRouterListener)
listeners) (\s :: VirtualRouterSpec
s@VirtualRouterSpec' {} Maybe (NonEmpty VirtualRouterListener)
a -> VirtualRouterSpec
s {$sel:listeners:VirtualRouterSpec' :: Maybe (NonEmpty VirtualRouterListener)
listeners = Maybe (NonEmpty VirtualRouterListener)
a} :: VirtualRouterSpec) ((Maybe (NonEmpty VirtualRouterListener)
  -> f (Maybe (NonEmpty VirtualRouterListener)))
 -> VirtualRouterSpec -> f VirtualRouterSpec)
-> ((Maybe (NonEmpty VirtualRouterListener)
     -> f (Maybe (NonEmpty VirtualRouterListener)))
    -> Maybe (NonEmpty VirtualRouterListener)
    -> f (Maybe (NonEmpty VirtualRouterListener)))
-> (Maybe (NonEmpty VirtualRouterListener)
    -> f (Maybe (NonEmpty VirtualRouterListener)))
-> VirtualRouterSpec
-> f VirtualRouterSpec
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty VirtualRouterListener)
  (NonEmpty VirtualRouterListener)
  (NonEmpty VirtualRouterListener)
  (NonEmpty VirtualRouterListener)
-> Iso
     (Maybe (NonEmpty VirtualRouterListener))
     (Maybe (NonEmpty VirtualRouterListener))
     (Maybe (NonEmpty VirtualRouterListener))
     (Maybe (NonEmpty VirtualRouterListener))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (NonEmpty VirtualRouterListener)
  (NonEmpty VirtualRouterListener)
  (NonEmpty VirtualRouterListener)
  (NonEmpty VirtualRouterListener)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable VirtualRouterSpec

instance Prelude.NFData VirtualRouterSpec

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