{-# 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.DirectConnect.Types.RouteFilterPrefix
-- 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.DirectConnect.Types.RouteFilterPrefix where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information about a route filter prefix that a customer can advertise
-- through Border Gateway Protocol (BGP) over a public virtual interface.
--
-- /See:/ 'newRouteFilterPrefix' smart constructor.
data RouteFilterPrefix = RouteFilterPrefix'
  { -- | The CIDR block for the advertised route. Separate multiple routes using
    -- commas. An IPv6 CIDR must use \/64 or shorter.
    RouteFilterPrefix -> Maybe Text
cidr :: Prelude.Maybe Prelude.Text
  }
  deriving (RouteFilterPrefix -> RouteFilterPrefix -> Bool
(RouteFilterPrefix -> RouteFilterPrefix -> Bool)
-> (RouteFilterPrefix -> RouteFilterPrefix -> Bool)
-> Eq RouteFilterPrefix
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RouteFilterPrefix -> RouteFilterPrefix -> Bool
$c/= :: RouteFilterPrefix -> RouteFilterPrefix -> Bool
== :: RouteFilterPrefix -> RouteFilterPrefix -> Bool
$c== :: RouteFilterPrefix -> RouteFilterPrefix -> Bool
Prelude.Eq, ReadPrec [RouteFilterPrefix]
ReadPrec RouteFilterPrefix
Int -> ReadS RouteFilterPrefix
ReadS [RouteFilterPrefix]
(Int -> ReadS RouteFilterPrefix)
-> ReadS [RouteFilterPrefix]
-> ReadPrec RouteFilterPrefix
-> ReadPrec [RouteFilterPrefix]
-> Read RouteFilterPrefix
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RouteFilterPrefix]
$creadListPrec :: ReadPrec [RouteFilterPrefix]
readPrec :: ReadPrec RouteFilterPrefix
$creadPrec :: ReadPrec RouteFilterPrefix
readList :: ReadS [RouteFilterPrefix]
$creadList :: ReadS [RouteFilterPrefix]
readsPrec :: Int -> ReadS RouteFilterPrefix
$creadsPrec :: Int -> ReadS RouteFilterPrefix
Prelude.Read, Int -> RouteFilterPrefix -> ShowS
[RouteFilterPrefix] -> ShowS
RouteFilterPrefix -> String
(Int -> RouteFilterPrefix -> ShowS)
-> (RouteFilterPrefix -> String)
-> ([RouteFilterPrefix] -> ShowS)
-> Show RouteFilterPrefix
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RouteFilterPrefix] -> ShowS
$cshowList :: [RouteFilterPrefix] -> ShowS
show :: RouteFilterPrefix -> String
$cshow :: RouteFilterPrefix -> String
showsPrec :: Int -> RouteFilterPrefix -> ShowS
$cshowsPrec :: Int -> RouteFilterPrefix -> ShowS
Prelude.Show, (forall x. RouteFilterPrefix -> Rep RouteFilterPrefix x)
-> (forall x. Rep RouteFilterPrefix x -> RouteFilterPrefix)
-> Generic RouteFilterPrefix
forall x. Rep RouteFilterPrefix x -> RouteFilterPrefix
forall x. RouteFilterPrefix -> Rep RouteFilterPrefix x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RouteFilterPrefix x -> RouteFilterPrefix
$cfrom :: forall x. RouteFilterPrefix -> Rep RouteFilterPrefix x
Prelude.Generic)

-- |
-- Create a value of 'RouteFilterPrefix' 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:
--
-- 'cidr', 'routeFilterPrefix_cidr' - The CIDR block for the advertised route. Separate multiple routes using
-- commas. An IPv6 CIDR must use \/64 or shorter.
newRouteFilterPrefix ::
  RouteFilterPrefix
newRouteFilterPrefix :: RouteFilterPrefix
newRouteFilterPrefix =
  RouteFilterPrefix' :: Maybe Text -> RouteFilterPrefix
RouteFilterPrefix' {$sel:cidr:RouteFilterPrefix' :: Maybe Text
cidr = Maybe Text
forall a. Maybe a
Prelude.Nothing}

-- | The CIDR block for the advertised route. Separate multiple routes using
-- commas. An IPv6 CIDR must use \/64 or shorter.
routeFilterPrefix_cidr :: Lens.Lens' RouteFilterPrefix (Prelude.Maybe Prelude.Text)
routeFilterPrefix_cidr :: (Maybe Text -> f (Maybe Text))
-> RouteFilterPrefix -> f RouteFilterPrefix
routeFilterPrefix_cidr = (RouteFilterPrefix -> Maybe Text)
-> (RouteFilterPrefix -> Maybe Text -> RouteFilterPrefix)
-> Lens
     RouteFilterPrefix RouteFilterPrefix (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RouteFilterPrefix' {Maybe Text
cidr :: Maybe Text
$sel:cidr:RouteFilterPrefix' :: RouteFilterPrefix -> Maybe Text
cidr} -> Maybe Text
cidr) (\s :: RouteFilterPrefix
s@RouteFilterPrefix' {} Maybe Text
a -> RouteFilterPrefix
s {$sel:cidr:RouteFilterPrefix' :: Maybe Text
cidr = Maybe Text
a} :: RouteFilterPrefix)

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

instance Prelude.Hashable RouteFilterPrefix

instance Prelude.NFData RouteFilterPrefix

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