{-# 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.CognitoIdentityProvider.Types.StringAttributeConstraintsType
-- 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.CognitoIdentityProvider.Types.StringAttributeConstraintsType where

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

-- | The constraints associated with a string attribute.
--
-- /See:/ 'newStringAttributeConstraintsType' smart constructor.
data StringAttributeConstraintsType = StringAttributeConstraintsType'
  { -- | The maximum length.
    StringAttributeConstraintsType -> Maybe Text
maxLength :: Prelude.Maybe Prelude.Text,
    -- | The minimum length.
    StringAttributeConstraintsType -> Maybe Text
minLength :: Prelude.Maybe Prelude.Text
  }
  deriving (StringAttributeConstraintsType
-> StringAttributeConstraintsType -> Bool
(StringAttributeConstraintsType
 -> StringAttributeConstraintsType -> Bool)
-> (StringAttributeConstraintsType
    -> StringAttributeConstraintsType -> Bool)
-> Eq StringAttributeConstraintsType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StringAttributeConstraintsType
-> StringAttributeConstraintsType -> Bool
$c/= :: StringAttributeConstraintsType
-> StringAttributeConstraintsType -> Bool
== :: StringAttributeConstraintsType
-> StringAttributeConstraintsType -> Bool
$c== :: StringAttributeConstraintsType
-> StringAttributeConstraintsType -> Bool
Prelude.Eq, ReadPrec [StringAttributeConstraintsType]
ReadPrec StringAttributeConstraintsType
Int -> ReadS StringAttributeConstraintsType
ReadS [StringAttributeConstraintsType]
(Int -> ReadS StringAttributeConstraintsType)
-> ReadS [StringAttributeConstraintsType]
-> ReadPrec StringAttributeConstraintsType
-> ReadPrec [StringAttributeConstraintsType]
-> Read StringAttributeConstraintsType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StringAttributeConstraintsType]
$creadListPrec :: ReadPrec [StringAttributeConstraintsType]
readPrec :: ReadPrec StringAttributeConstraintsType
$creadPrec :: ReadPrec StringAttributeConstraintsType
readList :: ReadS [StringAttributeConstraintsType]
$creadList :: ReadS [StringAttributeConstraintsType]
readsPrec :: Int -> ReadS StringAttributeConstraintsType
$creadsPrec :: Int -> ReadS StringAttributeConstraintsType
Prelude.Read, Int -> StringAttributeConstraintsType -> ShowS
[StringAttributeConstraintsType] -> ShowS
StringAttributeConstraintsType -> String
(Int -> StringAttributeConstraintsType -> ShowS)
-> (StringAttributeConstraintsType -> String)
-> ([StringAttributeConstraintsType] -> ShowS)
-> Show StringAttributeConstraintsType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StringAttributeConstraintsType] -> ShowS
$cshowList :: [StringAttributeConstraintsType] -> ShowS
show :: StringAttributeConstraintsType -> String
$cshow :: StringAttributeConstraintsType -> String
showsPrec :: Int -> StringAttributeConstraintsType -> ShowS
$cshowsPrec :: Int -> StringAttributeConstraintsType -> ShowS
Prelude.Show, (forall x.
 StringAttributeConstraintsType
 -> Rep StringAttributeConstraintsType x)
-> (forall x.
    Rep StringAttributeConstraintsType x
    -> StringAttributeConstraintsType)
-> Generic StringAttributeConstraintsType
forall x.
Rep StringAttributeConstraintsType x
-> StringAttributeConstraintsType
forall x.
StringAttributeConstraintsType
-> Rep StringAttributeConstraintsType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep StringAttributeConstraintsType x
-> StringAttributeConstraintsType
$cfrom :: forall x.
StringAttributeConstraintsType
-> Rep StringAttributeConstraintsType x
Prelude.Generic)

-- |
-- Create a value of 'StringAttributeConstraintsType' 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:
--
-- 'maxLength', 'stringAttributeConstraintsType_maxLength' - The maximum length.
--
-- 'minLength', 'stringAttributeConstraintsType_minLength' - The minimum length.
newStringAttributeConstraintsType ::
  StringAttributeConstraintsType
newStringAttributeConstraintsType :: StringAttributeConstraintsType
newStringAttributeConstraintsType =
  StringAttributeConstraintsType' :: Maybe Text -> Maybe Text -> StringAttributeConstraintsType
StringAttributeConstraintsType'
    { $sel:maxLength:StringAttributeConstraintsType' :: Maybe Text
maxLength =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:minLength:StringAttributeConstraintsType' :: Maybe Text
minLength = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum length.
stringAttributeConstraintsType_maxLength :: Lens.Lens' StringAttributeConstraintsType (Prelude.Maybe Prelude.Text)
stringAttributeConstraintsType_maxLength :: (Maybe Text -> f (Maybe Text))
-> StringAttributeConstraintsType
-> f StringAttributeConstraintsType
stringAttributeConstraintsType_maxLength = (StringAttributeConstraintsType -> Maybe Text)
-> (StringAttributeConstraintsType
    -> Maybe Text -> StringAttributeConstraintsType)
-> Lens
     StringAttributeConstraintsType
     StringAttributeConstraintsType
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StringAttributeConstraintsType' {Maybe Text
maxLength :: Maybe Text
$sel:maxLength:StringAttributeConstraintsType' :: StringAttributeConstraintsType -> Maybe Text
maxLength} -> Maybe Text
maxLength) (\s :: StringAttributeConstraintsType
s@StringAttributeConstraintsType' {} Maybe Text
a -> StringAttributeConstraintsType
s {$sel:maxLength:StringAttributeConstraintsType' :: Maybe Text
maxLength = Maybe Text
a} :: StringAttributeConstraintsType)

-- | The minimum length.
stringAttributeConstraintsType_minLength :: Lens.Lens' StringAttributeConstraintsType (Prelude.Maybe Prelude.Text)
stringAttributeConstraintsType_minLength :: (Maybe Text -> f (Maybe Text))
-> StringAttributeConstraintsType
-> f StringAttributeConstraintsType
stringAttributeConstraintsType_minLength = (StringAttributeConstraintsType -> Maybe Text)
-> (StringAttributeConstraintsType
    -> Maybe Text -> StringAttributeConstraintsType)
-> Lens
     StringAttributeConstraintsType
     StringAttributeConstraintsType
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StringAttributeConstraintsType' {Maybe Text
minLength :: Maybe Text
$sel:minLength:StringAttributeConstraintsType' :: StringAttributeConstraintsType -> Maybe Text
minLength} -> Maybe Text
minLength) (\s :: StringAttributeConstraintsType
s@StringAttributeConstraintsType' {} Maybe Text
a -> StringAttributeConstraintsType
s {$sel:minLength:StringAttributeConstraintsType' :: Maybe Text
minLength = Maybe Text
a} :: StringAttributeConstraintsType)

instance Core.FromJSON StringAttributeConstraintsType where
  parseJSON :: Value -> Parser StringAttributeConstraintsType
parseJSON =
    String
-> (Object -> Parser StringAttributeConstraintsType)
-> Value
-> Parser StringAttributeConstraintsType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"StringAttributeConstraintsType"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> StringAttributeConstraintsType
StringAttributeConstraintsType'
            (Maybe Text -> Maybe Text -> StringAttributeConstraintsType)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> StringAttributeConstraintsType)
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
"MaxLength")
            Parser (Maybe Text -> StringAttributeConstraintsType)
-> Parser (Maybe Text) -> Parser StringAttributeConstraintsType
forall (f :: * -> *) a b. Applicative f => 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
"MinLength")
      )

instance
  Prelude.Hashable
    StringAttributeConstraintsType

instance
  Prelude.NFData
    StringAttributeConstraintsType

instance Core.ToJSON StringAttributeConstraintsType where
  toJSON :: StringAttributeConstraintsType -> Value
toJSON StringAttributeConstraintsType' {Maybe Text
minLength :: Maybe Text
maxLength :: Maybe Text
$sel:minLength:StringAttributeConstraintsType' :: StringAttributeConstraintsType -> Maybe Text
$sel:maxLength:StringAttributeConstraintsType' :: StringAttributeConstraintsType -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"MaxLength" 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
maxLength,
            (Text
"MinLength" 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
minLength
          ]
      )