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

import Amazonka.AppMesh.Types.GrpcGatewayRoute
import Amazonka.AppMesh.Types.HttpGatewayRoute
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that represents a gateway route specification. Specify one
-- gateway route type.
--
-- /See:/ 'newGatewayRouteSpec' smart constructor.
data GatewayRouteSpec = GatewayRouteSpec'
  { -- | The ordering of the gateway routes spec.
    GatewayRouteSpec -> Maybe Natural
priority :: Prelude.Maybe Prelude.Natural,
    -- | An object that represents the specification of an HTTP\/2 gateway route.
    GatewayRouteSpec -> Maybe HttpGatewayRoute
http2Route :: Prelude.Maybe HttpGatewayRoute,
    -- | An object that represents the specification of a gRPC gateway route.
    GatewayRouteSpec -> Maybe GrpcGatewayRoute
grpcRoute :: Prelude.Maybe GrpcGatewayRoute,
    -- | An object that represents the specification of an HTTP gateway route.
    GatewayRouteSpec -> Maybe HttpGatewayRoute
httpRoute :: Prelude.Maybe HttpGatewayRoute
  }
  deriving (GatewayRouteSpec -> GatewayRouteSpec -> Bool
(GatewayRouteSpec -> GatewayRouteSpec -> Bool)
-> (GatewayRouteSpec -> GatewayRouteSpec -> Bool)
-> Eq GatewayRouteSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GatewayRouteSpec -> GatewayRouteSpec -> Bool
$c/= :: GatewayRouteSpec -> GatewayRouteSpec -> Bool
== :: GatewayRouteSpec -> GatewayRouteSpec -> Bool
$c== :: GatewayRouteSpec -> GatewayRouteSpec -> Bool
Prelude.Eq, ReadPrec [GatewayRouteSpec]
ReadPrec GatewayRouteSpec
Int -> ReadS GatewayRouteSpec
ReadS [GatewayRouteSpec]
(Int -> ReadS GatewayRouteSpec)
-> ReadS [GatewayRouteSpec]
-> ReadPrec GatewayRouteSpec
-> ReadPrec [GatewayRouteSpec]
-> Read GatewayRouteSpec
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GatewayRouteSpec]
$creadListPrec :: ReadPrec [GatewayRouteSpec]
readPrec :: ReadPrec GatewayRouteSpec
$creadPrec :: ReadPrec GatewayRouteSpec
readList :: ReadS [GatewayRouteSpec]
$creadList :: ReadS [GatewayRouteSpec]
readsPrec :: Int -> ReadS GatewayRouteSpec
$creadsPrec :: Int -> ReadS GatewayRouteSpec
Prelude.Read, Int -> GatewayRouteSpec -> ShowS
[GatewayRouteSpec] -> ShowS
GatewayRouteSpec -> String
(Int -> GatewayRouteSpec -> ShowS)
-> (GatewayRouteSpec -> String)
-> ([GatewayRouteSpec] -> ShowS)
-> Show GatewayRouteSpec
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GatewayRouteSpec] -> ShowS
$cshowList :: [GatewayRouteSpec] -> ShowS
show :: GatewayRouteSpec -> String
$cshow :: GatewayRouteSpec -> String
showsPrec :: Int -> GatewayRouteSpec -> ShowS
$cshowsPrec :: Int -> GatewayRouteSpec -> ShowS
Prelude.Show, (forall x. GatewayRouteSpec -> Rep GatewayRouteSpec x)
-> (forall x. Rep GatewayRouteSpec x -> GatewayRouteSpec)
-> Generic GatewayRouteSpec
forall x. Rep GatewayRouteSpec x -> GatewayRouteSpec
forall x. GatewayRouteSpec -> Rep GatewayRouteSpec x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GatewayRouteSpec x -> GatewayRouteSpec
$cfrom :: forall x. GatewayRouteSpec -> Rep GatewayRouteSpec x
Prelude.Generic)

-- |
-- Create a value of 'GatewayRouteSpec' 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:
--
-- 'priority', 'gatewayRouteSpec_priority' - The ordering of the gateway routes spec.
--
-- 'http2Route', 'gatewayRouteSpec_http2Route' - An object that represents the specification of an HTTP\/2 gateway route.
--
-- 'grpcRoute', 'gatewayRouteSpec_grpcRoute' - An object that represents the specification of a gRPC gateway route.
--
-- 'httpRoute', 'gatewayRouteSpec_httpRoute' - An object that represents the specification of an HTTP gateway route.
newGatewayRouteSpec ::
  GatewayRouteSpec
newGatewayRouteSpec :: GatewayRouteSpec
newGatewayRouteSpec =
  GatewayRouteSpec' :: Maybe Natural
-> Maybe HttpGatewayRoute
-> Maybe GrpcGatewayRoute
-> Maybe HttpGatewayRoute
-> GatewayRouteSpec
GatewayRouteSpec'
    { $sel:priority:GatewayRouteSpec' :: Maybe Natural
priority = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:http2Route:GatewayRouteSpec' :: Maybe HttpGatewayRoute
http2Route = Maybe HttpGatewayRoute
forall a. Maybe a
Prelude.Nothing,
      $sel:grpcRoute:GatewayRouteSpec' :: Maybe GrpcGatewayRoute
grpcRoute = Maybe GrpcGatewayRoute
forall a. Maybe a
Prelude.Nothing,
      $sel:httpRoute:GatewayRouteSpec' :: Maybe HttpGatewayRoute
httpRoute = Maybe HttpGatewayRoute
forall a. Maybe a
Prelude.Nothing
    }

-- | The ordering of the gateway routes spec.
gatewayRouteSpec_priority :: Lens.Lens' GatewayRouteSpec (Prelude.Maybe Prelude.Natural)
gatewayRouteSpec_priority :: (Maybe Natural -> f (Maybe Natural))
-> GatewayRouteSpec -> f GatewayRouteSpec
gatewayRouteSpec_priority = (GatewayRouteSpec -> Maybe Natural)
-> (GatewayRouteSpec -> Maybe Natural -> GatewayRouteSpec)
-> Lens
     GatewayRouteSpec GatewayRouteSpec (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatewayRouteSpec' {Maybe Natural
priority :: Maybe Natural
$sel:priority:GatewayRouteSpec' :: GatewayRouteSpec -> Maybe Natural
priority} -> Maybe Natural
priority) (\s :: GatewayRouteSpec
s@GatewayRouteSpec' {} Maybe Natural
a -> GatewayRouteSpec
s {$sel:priority:GatewayRouteSpec' :: Maybe Natural
priority = Maybe Natural
a} :: GatewayRouteSpec)

-- | An object that represents the specification of an HTTP\/2 gateway route.
gatewayRouteSpec_http2Route :: Lens.Lens' GatewayRouteSpec (Prelude.Maybe HttpGatewayRoute)
gatewayRouteSpec_http2Route :: (Maybe HttpGatewayRoute -> f (Maybe HttpGatewayRoute))
-> GatewayRouteSpec -> f GatewayRouteSpec
gatewayRouteSpec_http2Route = (GatewayRouteSpec -> Maybe HttpGatewayRoute)
-> (GatewayRouteSpec -> Maybe HttpGatewayRoute -> GatewayRouteSpec)
-> Lens
     GatewayRouteSpec
     GatewayRouteSpec
     (Maybe HttpGatewayRoute)
     (Maybe HttpGatewayRoute)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatewayRouteSpec' {Maybe HttpGatewayRoute
http2Route :: Maybe HttpGatewayRoute
$sel:http2Route:GatewayRouteSpec' :: GatewayRouteSpec -> Maybe HttpGatewayRoute
http2Route} -> Maybe HttpGatewayRoute
http2Route) (\s :: GatewayRouteSpec
s@GatewayRouteSpec' {} Maybe HttpGatewayRoute
a -> GatewayRouteSpec
s {$sel:http2Route:GatewayRouteSpec' :: Maybe HttpGatewayRoute
http2Route = Maybe HttpGatewayRoute
a} :: GatewayRouteSpec)

-- | An object that represents the specification of a gRPC gateway route.
gatewayRouteSpec_grpcRoute :: Lens.Lens' GatewayRouteSpec (Prelude.Maybe GrpcGatewayRoute)
gatewayRouteSpec_grpcRoute :: (Maybe GrpcGatewayRoute -> f (Maybe GrpcGatewayRoute))
-> GatewayRouteSpec -> f GatewayRouteSpec
gatewayRouteSpec_grpcRoute = (GatewayRouteSpec -> Maybe GrpcGatewayRoute)
-> (GatewayRouteSpec -> Maybe GrpcGatewayRoute -> GatewayRouteSpec)
-> Lens
     GatewayRouteSpec
     GatewayRouteSpec
     (Maybe GrpcGatewayRoute)
     (Maybe GrpcGatewayRoute)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatewayRouteSpec' {Maybe GrpcGatewayRoute
grpcRoute :: Maybe GrpcGatewayRoute
$sel:grpcRoute:GatewayRouteSpec' :: GatewayRouteSpec -> Maybe GrpcGatewayRoute
grpcRoute} -> Maybe GrpcGatewayRoute
grpcRoute) (\s :: GatewayRouteSpec
s@GatewayRouteSpec' {} Maybe GrpcGatewayRoute
a -> GatewayRouteSpec
s {$sel:grpcRoute:GatewayRouteSpec' :: Maybe GrpcGatewayRoute
grpcRoute = Maybe GrpcGatewayRoute
a} :: GatewayRouteSpec)

-- | An object that represents the specification of an HTTP gateway route.
gatewayRouteSpec_httpRoute :: Lens.Lens' GatewayRouteSpec (Prelude.Maybe HttpGatewayRoute)
gatewayRouteSpec_httpRoute :: (Maybe HttpGatewayRoute -> f (Maybe HttpGatewayRoute))
-> GatewayRouteSpec -> f GatewayRouteSpec
gatewayRouteSpec_httpRoute = (GatewayRouteSpec -> Maybe HttpGatewayRoute)
-> (GatewayRouteSpec -> Maybe HttpGatewayRoute -> GatewayRouteSpec)
-> Lens
     GatewayRouteSpec
     GatewayRouteSpec
     (Maybe HttpGatewayRoute)
     (Maybe HttpGatewayRoute)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatewayRouteSpec' {Maybe HttpGatewayRoute
httpRoute :: Maybe HttpGatewayRoute
$sel:httpRoute:GatewayRouteSpec' :: GatewayRouteSpec -> Maybe HttpGatewayRoute
httpRoute} -> Maybe HttpGatewayRoute
httpRoute) (\s :: GatewayRouteSpec
s@GatewayRouteSpec' {} Maybe HttpGatewayRoute
a -> GatewayRouteSpec
s {$sel:httpRoute:GatewayRouteSpec' :: Maybe HttpGatewayRoute
httpRoute = Maybe HttpGatewayRoute
a} :: GatewayRouteSpec)

instance Core.FromJSON GatewayRouteSpec where
  parseJSON :: Value -> Parser GatewayRouteSpec
parseJSON =
    String
-> (Object -> Parser GatewayRouteSpec)
-> Value
-> Parser GatewayRouteSpec
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"GatewayRouteSpec"
      ( \Object
x ->
          Maybe Natural
-> Maybe HttpGatewayRoute
-> Maybe GrpcGatewayRoute
-> Maybe HttpGatewayRoute
-> GatewayRouteSpec
GatewayRouteSpec'
            (Maybe Natural
 -> Maybe HttpGatewayRoute
 -> Maybe GrpcGatewayRoute
 -> Maybe HttpGatewayRoute
 -> GatewayRouteSpec)
-> Parser (Maybe Natural)
-> Parser
     (Maybe HttpGatewayRoute
      -> Maybe GrpcGatewayRoute
      -> Maybe HttpGatewayRoute
      -> GatewayRouteSpec)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"priority")
            Parser
  (Maybe HttpGatewayRoute
   -> Maybe GrpcGatewayRoute
   -> Maybe HttpGatewayRoute
   -> GatewayRouteSpec)
-> Parser (Maybe HttpGatewayRoute)
-> Parser
     (Maybe GrpcGatewayRoute
      -> Maybe HttpGatewayRoute -> GatewayRouteSpec)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe HttpGatewayRoute)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"http2Route")
            Parser
  (Maybe GrpcGatewayRoute
   -> Maybe HttpGatewayRoute -> GatewayRouteSpec)
-> Parser (Maybe GrpcGatewayRoute)
-> Parser (Maybe HttpGatewayRoute -> GatewayRouteSpec)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe GrpcGatewayRoute)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"grpcRoute")
            Parser (Maybe HttpGatewayRoute -> GatewayRouteSpec)
-> Parser (Maybe HttpGatewayRoute) -> Parser GatewayRouteSpec
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe HttpGatewayRoute)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"httpRoute")
      )

instance Prelude.Hashable GatewayRouteSpec

instance Prelude.NFData GatewayRouteSpec

instance Core.ToJSON GatewayRouteSpec where
  toJSON :: GatewayRouteSpec -> Value
toJSON GatewayRouteSpec' {Maybe Natural
Maybe GrpcGatewayRoute
Maybe HttpGatewayRoute
httpRoute :: Maybe HttpGatewayRoute
grpcRoute :: Maybe GrpcGatewayRoute
http2Route :: Maybe HttpGatewayRoute
priority :: Maybe Natural
$sel:httpRoute:GatewayRouteSpec' :: GatewayRouteSpec -> Maybe HttpGatewayRoute
$sel:grpcRoute:GatewayRouteSpec' :: GatewayRouteSpec -> Maybe GrpcGatewayRoute
$sel:http2Route:GatewayRouteSpec' :: GatewayRouteSpec -> Maybe HttpGatewayRoute
$sel:priority:GatewayRouteSpec' :: GatewayRouteSpec -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"priority" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
priority,
            (Text
"http2Route" Text -> HttpGatewayRoute -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HttpGatewayRoute -> Pair) -> Maybe HttpGatewayRoute -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe HttpGatewayRoute
http2Route,
            (Text
"grpcRoute" Text -> GrpcGatewayRoute -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (GrpcGatewayRoute -> Pair) -> Maybe GrpcGatewayRoute -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe GrpcGatewayRoute
grpcRoute,
            (Text
"httpRoute" Text -> HttpGatewayRoute -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HttpGatewayRoute -> Pair) -> Maybe HttpGatewayRoute -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe HttpGatewayRoute
httpRoute
          ]
      )