{-# 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.TokenValidityUnitsType
-- 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.TokenValidityUnitsType where

import Amazonka.CognitoIdentityProvider.Types.TimeUnitsType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The data type for TokenValidityUnits that specifics the time
-- measurements for token validity.
--
-- /See:/ 'newTokenValidityUnitsType' smart constructor.
data TokenValidityUnitsType = TokenValidityUnitsType'
  { -- | A time unit in “seconds”, “minutes”, “hours” or “days” for the value in
    -- AccessTokenValidity, defaults to hours.
    TokenValidityUnitsType -> Maybe TimeUnitsType
accessToken :: Prelude.Maybe TimeUnitsType,
    -- | A time unit in “seconds”, “minutes”, “hours” or “days” for the value in
    -- RefreshTokenValidity, defaults to days.
    TokenValidityUnitsType -> Maybe TimeUnitsType
refreshToken :: Prelude.Maybe TimeUnitsType,
    -- | A time unit in “seconds”, “minutes”, “hours” or “days” for the value in
    -- IdTokenValidity, defaults to hours.
    TokenValidityUnitsType -> Maybe TimeUnitsType
idToken :: Prelude.Maybe TimeUnitsType
  }
  deriving (TokenValidityUnitsType -> TokenValidityUnitsType -> Bool
(TokenValidityUnitsType -> TokenValidityUnitsType -> Bool)
-> (TokenValidityUnitsType -> TokenValidityUnitsType -> Bool)
-> Eq TokenValidityUnitsType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TokenValidityUnitsType -> TokenValidityUnitsType -> Bool
$c/= :: TokenValidityUnitsType -> TokenValidityUnitsType -> Bool
== :: TokenValidityUnitsType -> TokenValidityUnitsType -> Bool
$c== :: TokenValidityUnitsType -> TokenValidityUnitsType -> Bool
Prelude.Eq, ReadPrec [TokenValidityUnitsType]
ReadPrec TokenValidityUnitsType
Int -> ReadS TokenValidityUnitsType
ReadS [TokenValidityUnitsType]
(Int -> ReadS TokenValidityUnitsType)
-> ReadS [TokenValidityUnitsType]
-> ReadPrec TokenValidityUnitsType
-> ReadPrec [TokenValidityUnitsType]
-> Read TokenValidityUnitsType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TokenValidityUnitsType]
$creadListPrec :: ReadPrec [TokenValidityUnitsType]
readPrec :: ReadPrec TokenValidityUnitsType
$creadPrec :: ReadPrec TokenValidityUnitsType
readList :: ReadS [TokenValidityUnitsType]
$creadList :: ReadS [TokenValidityUnitsType]
readsPrec :: Int -> ReadS TokenValidityUnitsType
$creadsPrec :: Int -> ReadS TokenValidityUnitsType
Prelude.Read, Int -> TokenValidityUnitsType -> ShowS
[TokenValidityUnitsType] -> ShowS
TokenValidityUnitsType -> String
(Int -> TokenValidityUnitsType -> ShowS)
-> (TokenValidityUnitsType -> String)
-> ([TokenValidityUnitsType] -> ShowS)
-> Show TokenValidityUnitsType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TokenValidityUnitsType] -> ShowS
$cshowList :: [TokenValidityUnitsType] -> ShowS
show :: TokenValidityUnitsType -> String
$cshow :: TokenValidityUnitsType -> String
showsPrec :: Int -> TokenValidityUnitsType -> ShowS
$cshowsPrec :: Int -> TokenValidityUnitsType -> ShowS
Prelude.Show, (forall x. TokenValidityUnitsType -> Rep TokenValidityUnitsType x)
-> (forall x.
    Rep TokenValidityUnitsType x -> TokenValidityUnitsType)
-> Generic TokenValidityUnitsType
forall x. Rep TokenValidityUnitsType x -> TokenValidityUnitsType
forall x. TokenValidityUnitsType -> Rep TokenValidityUnitsType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TokenValidityUnitsType x -> TokenValidityUnitsType
$cfrom :: forall x. TokenValidityUnitsType -> Rep TokenValidityUnitsType x
Prelude.Generic)

-- |
-- Create a value of 'TokenValidityUnitsType' 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:
--
-- 'accessToken', 'tokenValidityUnitsType_accessToken' - A time unit in “seconds”, “minutes”, “hours” or “days” for the value in
-- AccessTokenValidity, defaults to hours.
--
-- 'refreshToken', 'tokenValidityUnitsType_refreshToken' - A time unit in “seconds”, “minutes”, “hours” or “days” for the value in
-- RefreshTokenValidity, defaults to days.
--
-- 'idToken', 'tokenValidityUnitsType_idToken' - A time unit in “seconds”, “minutes”, “hours” or “days” for the value in
-- IdTokenValidity, defaults to hours.
newTokenValidityUnitsType ::
  TokenValidityUnitsType
newTokenValidityUnitsType :: TokenValidityUnitsType
newTokenValidityUnitsType =
  TokenValidityUnitsType' :: Maybe TimeUnitsType
-> Maybe TimeUnitsType
-> Maybe TimeUnitsType
-> TokenValidityUnitsType
TokenValidityUnitsType'
    { $sel:accessToken:TokenValidityUnitsType' :: Maybe TimeUnitsType
accessToken =
        Maybe TimeUnitsType
forall a. Maybe a
Prelude.Nothing,
      $sel:refreshToken:TokenValidityUnitsType' :: Maybe TimeUnitsType
refreshToken = Maybe TimeUnitsType
forall a. Maybe a
Prelude.Nothing,
      $sel:idToken:TokenValidityUnitsType' :: Maybe TimeUnitsType
idToken = Maybe TimeUnitsType
forall a. Maybe a
Prelude.Nothing
    }

-- | A time unit in “seconds”, “minutes”, “hours” or “days” for the value in
-- AccessTokenValidity, defaults to hours.
tokenValidityUnitsType_accessToken :: Lens.Lens' TokenValidityUnitsType (Prelude.Maybe TimeUnitsType)
tokenValidityUnitsType_accessToken :: (Maybe TimeUnitsType -> f (Maybe TimeUnitsType))
-> TokenValidityUnitsType -> f TokenValidityUnitsType
tokenValidityUnitsType_accessToken = (TokenValidityUnitsType -> Maybe TimeUnitsType)
-> (TokenValidityUnitsType
    -> Maybe TimeUnitsType -> TokenValidityUnitsType)
-> Lens
     TokenValidityUnitsType
     TokenValidityUnitsType
     (Maybe TimeUnitsType)
     (Maybe TimeUnitsType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TokenValidityUnitsType' {Maybe TimeUnitsType
accessToken :: Maybe TimeUnitsType
$sel:accessToken:TokenValidityUnitsType' :: TokenValidityUnitsType -> Maybe TimeUnitsType
accessToken} -> Maybe TimeUnitsType
accessToken) (\s :: TokenValidityUnitsType
s@TokenValidityUnitsType' {} Maybe TimeUnitsType
a -> TokenValidityUnitsType
s {$sel:accessToken:TokenValidityUnitsType' :: Maybe TimeUnitsType
accessToken = Maybe TimeUnitsType
a} :: TokenValidityUnitsType)

-- | A time unit in “seconds”, “minutes”, “hours” or “days” for the value in
-- RefreshTokenValidity, defaults to days.
tokenValidityUnitsType_refreshToken :: Lens.Lens' TokenValidityUnitsType (Prelude.Maybe TimeUnitsType)
tokenValidityUnitsType_refreshToken :: (Maybe TimeUnitsType -> f (Maybe TimeUnitsType))
-> TokenValidityUnitsType -> f TokenValidityUnitsType
tokenValidityUnitsType_refreshToken = (TokenValidityUnitsType -> Maybe TimeUnitsType)
-> (TokenValidityUnitsType
    -> Maybe TimeUnitsType -> TokenValidityUnitsType)
-> Lens
     TokenValidityUnitsType
     TokenValidityUnitsType
     (Maybe TimeUnitsType)
     (Maybe TimeUnitsType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TokenValidityUnitsType' {Maybe TimeUnitsType
refreshToken :: Maybe TimeUnitsType
$sel:refreshToken:TokenValidityUnitsType' :: TokenValidityUnitsType -> Maybe TimeUnitsType
refreshToken} -> Maybe TimeUnitsType
refreshToken) (\s :: TokenValidityUnitsType
s@TokenValidityUnitsType' {} Maybe TimeUnitsType
a -> TokenValidityUnitsType
s {$sel:refreshToken:TokenValidityUnitsType' :: Maybe TimeUnitsType
refreshToken = Maybe TimeUnitsType
a} :: TokenValidityUnitsType)

-- | A time unit in “seconds”, “minutes”, “hours” or “days” for the value in
-- IdTokenValidity, defaults to hours.
tokenValidityUnitsType_idToken :: Lens.Lens' TokenValidityUnitsType (Prelude.Maybe TimeUnitsType)
tokenValidityUnitsType_idToken :: (Maybe TimeUnitsType -> f (Maybe TimeUnitsType))
-> TokenValidityUnitsType -> f TokenValidityUnitsType
tokenValidityUnitsType_idToken = (TokenValidityUnitsType -> Maybe TimeUnitsType)
-> (TokenValidityUnitsType
    -> Maybe TimeUnitsType -> TokenValidityUnitsType)
-> Lens
     TokenValidityUnitsType
     TokenValidityUnitsType
     (Maybe TimeUnitsType)
     (Maybe TimeUnitsType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TokenValidityUnitsType' {Maybe TimeUnitsType
idToken :: Maybe TimeUnitsType
$sel:idToken:TokenValidityUnitsType' :: TokenValidityUnitsType -> Maybe TimeUnitsType
idToken} -> Maybe TimeUnitsType
idToken) (\s :: TokenValidityUnitsType
s@TokenValidityUnitsType' {} Maybe TimeUnitsType
a -> TokenValidityUnitsType
s {$sel:idToken:TokenValidityUnitsType' :: Maybe TimeUnitsType
idToken = Maybe TimeUnitsType
a} :: TokenValidityUnitsType)

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

instance Prelude.Hashable TokenValidityUnitsType

instance Prelude.NFData TokenValidityUnitsType

instance Core.ToJSON TokenValidityUnitsType where
  toJSON :: TokenValidityUnitsType -> Value
toJSON TokenValidityUnitsType' {Maybe TimeUnitsType
idToken :: Maybe TimeUnitsType
refreshToken :: Maybe TimeUnitsType
accessToken :: Maybe TimeUnitsType
$sel:idToken:TokenValidityUnitsType' :: TokenValidityUnitsType -> Maybe TimeUnitsType
$sel:refreshToken:TokenValidityUnitsType' :: TokenValidityUnitsType -> Maybe TimeUnitsType
$sel:accessToken:TokenValidityUnitsType' :: TokenValidityUnitsType -> Maybe TimeUnitsType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"AccessToken" Text -> TimeUnitsType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (TimeUnitsType -> Pair) -> Maybe TimeUnitsType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TimeUnitsType
accessToken,
            (Text
"RefreshToken" Text -> TimeUnitsType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (TimeUnitsType -> Pair) -> Maybe TimeUnitsType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TimeUnitsType
refreshToken,
            (Text
"IdToken" Text -> TimeUnitsType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (TimeUnitsType -> Pair) -> Maybe TimeUnitsType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TimeUnitsType
idToken
          ]
      )