{-# 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.WAF.Types.GeoMatchConstraint
-- 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.WAF.Types.GeoMatchConstraint where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.WAF.Types.GeoMatchConstraintType
import Amazonka.WAF.Types.GeoMatchConstraintValue

-- | This is __AWS WAF Classic__ documentation. For more information, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/classic-waf-chapter.html AWS WAF Classic>
-- in the developer guide.
--
-- __For the latest version of AWS WAF__, use the AWS WAFV2 API and see the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html AWS WAF Developer Guide>.
-- With the latest version, AWS WAF has a single set of endpoints for
-- regional and global use.
--
-- The country from which web requests originate that you want AWS WAF to
-- search for.
--
-- /See:/ 'newGeoMatchConstraint' smart constructor.
data GeoMatchConstraint = GeoMatchConstraint'
  { -- | The type of geographical area you want AWS WAF to search for. Currently
    -- @Country@ is the only valid value.
    GeoMatchConstraint -> GeoMatchConstraintType
type' :: GeoMatchConstraintType,
    -- | The country that you want AWS WAF to search for.
    GeoMatchConstraint -> GeoMatchConstraintValue
value :: GeoMatchConstraintValue
  }
  deriving (GeoMatchConstraint -> GeoMatchConstraint -> Bool
(GeoMatchConstraint -> GeoMatchConstraint -> Bool)
-> (GeoMatchConstraint -> GeoMatchConstraint -> Bool)
-> Eq GeoMatchConstraint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GeoMatchConstraint -> GeoMatchConstraint -> Bool
$c/= :: GeoMatchConstraint -> GeoMatchConstraint -> Bool
== :: GeoMatchConstraint -> GeoMatchConstraint -> Bool
$c== :: GeoMatchConstraint -> GeoMatchConstraint -> Bool
Prelude.Eq, ReadPrec [GeoMatchConstraint]
ReadPrec GeoMatchConstraint
Int -> ReadS GeoMatchConstraint
ReadS [GeoMatchConstraint]
(Int -> ReadS GeoMatchConstraint)
-> ReadS [GeoMatchConstraint]
-> ReadPrec GeoMatchConstraint
-> ReadPrec [GeoMatchConstraint]
-> Read GeoMatchConstraint
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GeoMatchConstraint]
$creadListPrec :: ReadPrec [GeoMatchConstraint]
readPrec :: ReadPrec GeoMatchConstraint
$creadPrec :: ReadPrec GeoMatchConstraint
readList :: ReadS [GeoMatchConstraint]
$creadList :: ReadS [GeoMatchConstraint]
readsPrec :: Int -> ReadS GeoMatchConstraint
$creadsPrec :: Int -> ReadS GeoMatchConstraint
Prelude.Read, Int -> GeoMatchConstraint -> ShowS
[GeoMatchConstraint] -> ShowS
GeoMatchConstraint -> String
(Int -> GeoMatchConstraint -> ShowS)
-> (GeoMatchConstraint -> String)
-> ([GeoMatchConstraint] -> ShowS)
-> Show GeoMatchConstraint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GeoMatchConstraint] -> ShowS
$cshowList :: [GeoMatchConstraint] -> ShowS
show :: GeoMatchConstraint -> String
$cshow :: GeoMatchConstraint -> String
showsPrec :: Int -> GeoMatchConstraint -> ShowS
$cshowsPrec :: Int -> GeoMatchConstraint -> ShowS
Prelude.Show, (forall x. GeoMatchConstraint -> Rep GeoMatchConstraint x)
-> (forall x. Rep GeoMatchConstraint x -> GeoMatchConstraint)
-> Generic GeoMatchConstraint
forall x. Rep GeoMatchConstraint x -> GeoMatchConstraint
forall x. GeoMatchConstraint -> Rep GeoMatchConstraint x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GeoMatchConstraint x -> GeoMatchConstraint
$cfrom :: forall x. GeoMatchConstraint -> Rep GeoMatchConstraint x
Prelude.Generic)

-- |
-- Create a value of 'GeoMatchConstraint' 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:
--
-- 'type'', 'geoMatchConstraint_type' - The type of geographical area you want AWS WAF to search for. Currently
-- @Country@ is the only valid value.
--
-- 'value', 'geoMatchConstraint_value' - The country that you want AWS WAF to search for.
newGeoMatchConstraint ::
  -- | 'type''
  GeoMatchConstraintType ->
  -- | 'value'
  GeoMatchConstraintValue ->
  GeoMatchConstraint
newGeoMatchConstraint :: GeoMatchConstraintType
-> GeoMatchConstraintValue -> GeoMatchConstraint
newGeoMatchConstraint GeoMatchConstraintType
pType_ GeoMatchConstraintValue
pValue_ =
  GeoMatchConstraint' :: GeoMatchConstraintType
-> GeoMatchConstraintValue -> GeoMatchConstraint
GeoMatchConstraint'
    { $sel:type':GeoMatchConstraint' :: GeoMatchConstraintType
type' = GeoMatchConstraintType
pType_,
      $sel:value:GeoMatchConstraint' :: GeoMatchConstraintValue
value = GeoMatchConstraintValue
pValue_
    }

-- | The type of geographical area you want AWS WAF to search for. Currently
-- @Country@ is the only valid value.
geoMatchConstraint_type :: Lens.Lens' GeoMatchConstraint GeoMatchConstraintType
geoMatchConstraint_type :: (GeoMatchConstraintType -> f GeoMatchConstraintType)
-> GeoMatchConstraint -> f GeoMatchConstraint
geoMatchConstraint_type = (GeoMatchConstraint -> GeoMatchConstraintType)
-> (GeoMatchConstraint
    -> GeoMatchConstraintType -> GeoMatchConstraint)
-> Lens
     GeoMatchConstraint
     GeoMatchConstraint
     GeoMatchConstraintType
     GeoMatchConstraintType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GeoMatchConstraint' {GeoMatchConstraintType
type' :: GeoMatchConstraintType
$sel:type':GeoMatchConstraint' :: GeoMatchConstraint -> GeoMatchConstraintType
type'} -> GeoMatchConstraintType
type') (\s :: GeoMatchConstraint
s@GeoMatchConstraint' {} GeoMatchConstraintType
a -> GeoMatchConstraint
s {$sel:type':GeoMatchConstraint' :: GeoMatchConstraintType
type' = GeoMatchConstraintType
a} :: GeoMatchConstraint)

-- | The country that you want AWS WAF to search for.
geoMatchConstraint_value :: Lens.Lens' GeoMatchConstraint GeoMatchConstraintValue
geoMatchConstraint_value :: (GeoMatchConstraintValue -> f GeoMatchConstraintValue)
-> GeoMatchConstraint -> f GeoMatchConstraint
geoMatchConstraint_value = (GeoMatchConstraint -> GeoMatchConstraintValue)
-> (GeoMatchConstraint
    -> GeoMatchConstraintValue -> GeoMatchConstraint)
-> Lens
     GeoMatchConstraint
     GeoMatchConstraint
     GeoMatchConstraintValue
     GeoMatchConstraintValue
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GeoMatchConstraint' {GeoMatchConstraintValue
value :: GeoMatchConstraintValue
$sel:value:GeoMatchConstraint' :: GeoMatchConstraint -> GeoMatchConstraintValue
value} -> GeoMatchConstraintValue
value) (\s :: GeoMatchConstraint
s@GeoMatchConstraint' {} GeoMatchConstraintValue
a -> GeoMatchConstraint
s {$sel:value:GeoMatchConstraint' :: GeoMatchConstraintValue
value = GeoMatchConstraintValue
a} :: GeoMatchConstraint)

instance Core.FromJSON GeoMatchConstraint where
  parseJSON :: Value -> Parser GeoMatchConstraint
parseJSON =
    String
-> (Object -> Parser GeoMatchConstraint)
-> Value
-> Parser GeoMatchConstraint
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"GeoMatchConstraint"
      ( \Object
x ->
          GeoMatchConstraintType
-> GeoMatchConstraintValue -> GeoMatchConstraint
GeoMatchConstraint'
            (GeoMatchConstraintType
 -> GeoMatchConstraintValue -> GeoMatchConstraint)
-> Parser GeoMatchConstraintType
-> Parser (GeoMatchConstraintValue -> GeoMatchConstraint)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser GeoMatchConstraintType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Type") Parser (GeoMatchConstraintValue -> GeoMatchConstraint)
-> Parser GeoMatchConstraintValue -> Parser GeoMatchConstraint
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser GeoMatchConstraintValue
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Value")
      )

instance Prelude.Hashable GeoMatchConstraint

instance Prelude.NFData GeoMatchConstraint

instance Core.ToJSON GeoMatchConstraint where
  toJSON :: GeoMatchConstraint -> Value
toJSON GeoMatchConstraint' {GeoMatchConstraintType
GeoMatchConstraintValue
value :: GeoMatchConstraintValue
type' :: GeoMatchConstraintType
$sel:value:GeoMatchConstraint' :: GeoMatchConstraint -> GeoMatchConstraintValue
$sel:type':GeoMatchConstraint' :: GeoMatchConstraint -> GeoMatchConstraintType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Type" Text -> GeoMatchConstraintType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= GeoMatchConstraintType
type'),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Value" Text -> GeoMatchConstraintValue -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= GeoMatchConstraintValue
value)
          ]
      )