{-# 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.ApiGatewayV2.Types.ParameterConstraints
-- 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.ApiGatewayV2.Types.ParameterConstraints where

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

-- | Validation constraints imposed on parameters of a request (path, query
-- string, headers).
--
-- /See:/ 'newParameterConstraints' smart constructor.
data ParameterConstraints = ParameterConstraints'
  { -- | Whether or not the parameter is required.
    ParameterConstraints -> Maybe Bool
required :: Prelude.Maybe Prelude.Bool
  }
  deriving (ParameterConstraints -> ParameterConstraints -> Bool
(ParameterConstraints -> ParameterConstraints -> Bool)
-> (ParameterConstraints -> ParameterConstraints -> Bool)
-> Eq ParameterConstraints
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ParameterConstraints -> ParameterConstraints -> Bool
$c/= :: ParameterConstraints -> ParameterConstraints -> Bool
== :: ParameterConstraints -> ParameterConstraints -> Bool
$c== :: ParameterConstraints -> ParameterConstraints -> Bool
Prelude.Eq, ReadPrec [ParameterConstraints]
ReadPrec ParameterConstraints
Int -> ReadS ParameterConstraints
ReadS [ParameterConstraints]
(Int -> ReadS ParameterConstraints)
-> ReadS [ParameterConstraints]
-> ReadPrec ParameterConstraints
-> ReadPrec [ParameterConstraints]
-> Read ParameterConstraints
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ParameterConstraints]
$creadListPrec :: ReadPrec [ParameterConstraints]
readPrec :: ReadPrec ParameterConstraints
$creadPrec :: ReadPrec ParameterConstraints
readList :: ReadS [ParameterConstraints]
$creadList :: ReadS [ParameterConstraints]
readsPrec :: Int -> ReadS ParameterConstraints
$creadsPrec :: Int -> ReadS ParameterConstraints
Prelude.Read, Int -> ParameterConstraints -> ShowS
[ParameterConstraints] -> ShowS
ParameterConstraints -> String
(Int -> ParameterConstraints -> ShowS)
-> (ParameterConstraints -> String)
-> ([ParameterConstraints] -> ShowS)
-> Show ParameterConstraints
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ParameterConstraints] -> ShowS
$cshowList :: [ParameterConstraints] -> ShowS
show :: ParameterConstraints -> String
$cshow :: ParameterConstraints -> String
showsPrec :: Int -> ParameterConstraints -> ShowS
$cshowsPrec :: Int -> ParameterConstraints -> ShowS
Prelude.Show, (forall x. ParameterConstraints -> Rep ParameterConstraints x)
-> (forall x. Rep ParameterConstraints x -> ParameterConstraints)
-> Generic ParameterConstraints
forall x. Rep ParameterConstraints x -> ParameterConstraints
forall x. ParameterConstraints -> Rep ParameterConstraints x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ParameterConstraints x -> ParameterConstraints
$cfrom :: forall x. ParameterConstraints -> Rep ParameterConstraints x
Prelude.Generic)

-- |
-- Create a value of 'ParameterConstraints' 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:
--
-- 'required', 'parameterConstraints_required' - Whether or not the parameter is required.
newParameterConstraints ::
  ParameterConstraints
newParameterConstraints :: ParameterConstraints
newParameterConstraints =
  ParameterConstraints' :: Maybe Bool -> ParameterConstraints
ParameterConstraints' {$sel:required:ParameterConstraints' :: Maybe Bool
required = Maybe Bool
forall a. Maybe a
Prelude.Nothing}

-- | Whether or not the parameter is required.
parameterConstraints_required :: Lens.Lens' ParameterConstraints (Prelude.Maybe Prelude.Bool)
parameterConstraints_required :: (Maybe Bool -> f (Maybe Bool))
-> ParameterConstraints -> f ParameterConstraints
parameterConstraints_required = (ParameterConstraints -> Maybe Bool)
-> (ParameterConstraints -> Maybe Bool -> ParameterConstraints)
-> Lens
     ParameterConstraints ParameterConstraints (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ParameterConstraints' {Maybe Bool
required :: Maybe Bool
$sel:required:ParameterConstraints' :: ParameterConstraints -> Maybe Bool
required} -> Maybe Bool
required) (\s :: ParameterConstraints
s@ParameterConstraints' {} Maybe Bool
a -> ParameterConstraints
s {$sel:required:ParameterConstraints' :: Maybe Bool
required = Maybe Bool
a} :: ParameterConstraints)

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

instance Prelude.Hashable ParameterConstraints

instance Prelude.NFData ParameterConstraints

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