{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CognitoIdentityProvider.Types.StringAttributeConstraintsType where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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.
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'
    { $sel:maxLength:StringAttributeConstraintsType' :: Maybe Text
maxLength =
        forall a. Maybe a
Prelude.Nothing,
      $sel:minLength:StringAttributeConstraintsType' :: Maybe Text
minLength = forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum length.
stringAttributeConstraintsType_maxLength :: Lens.Lens' StringAttributeConstraintsType (Prelude.Maybe Prelude.Text)
stringAttributeConstraintsType_maxLength :: Lens' StringAttributeConstraintsType (Maybe Text)
stringAttributeConstraintsType_maxLength = 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 :: Lens' StringAttributeConstraintsType (Maybe Text)
stringAttributeConstraintsType_minLength = 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 Data.FromJSON StringAttributeConstraintsType where
  parseJSON :: Value -> Parser StringAttributeConstraintsType
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"StringAttributeConstraintsType"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> StringAttributeConstraintsType
StringAttributeConstraintsType'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"MaxLength")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"MinLength")
      )

instance
  Prelude.Hashable
    StringAttributeConstraintsType
  where
  hashWithSalt :: Int -> StringAttributeConstraintsType -> Int
hashWithSalt
    Int
_salt
    StringAttributeConstraintsType' {Maybe Text
minLength :: Maybe Text
maxLength :: Maybe Text
$sel:minLength:StringAttributeConstraintsType' :: StringAttributeConstraintsType -> Maybe Text
$sel:maxLength:StringAttributeConstraintsType' :: StringAttributeConstraintsType -> Maybe Text
..} =
      Int
_salt
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
maxLength
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
minLength

instance
  Prelude.NFData
    StringAttributeConstraintsType
  where
  rnf :: StringAttributeConstraintsType -> ()
rnf StringAttributeConstraintsType' {Maybe Text
minLength :: Maybe Text
maxLength :: Maybe Text
$sel:minLength:StringAttributeConstraintsType' :: StringAttributeConstraintsType -> Maybe Text
$sel:maxLength:StringAttributeConstraintsType' :: StringAttributeConstraintsType -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
maxLength
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
minLength

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"MaxLength" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
maxLength,
            (Key
"MinLength" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
minLength
          ]
      )