{-# 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.UserContextDataType
-- 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.UserContextDataType 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

-- | Contextual data, such as the user\'s device fingerprint, IP address, or
-- location, used for evaluating the risk of an unexpected event by Amazon
-- Cognito advanced security.
--
-- /See:/ 'newUserContextDataType' smart constructor.
data UserContextDataType = UserContextDataType'
  { -- | Encoded device-fingerprint details that your app collected with the
    -- Amazon Cognito context data collection library. For more information,
    -- see
    -- <https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pool-settings-adaptive-authentication.html#user-pool-settings-adaptive-authentication-device-fingerprint Adding user device and session data to API requests>.
    UserContextDataType -> Maybe Text
encodedData :: Prelude.Maybe Prelude.Text,
    -- | The source IP address of your user\'s device.
    UserContextDataType -> Maybe Text
ipAddress :: Prelude.Maybe Prelude.Text
  }
  deriving (UserContextDataType -> UserContextDataType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UserContextDataType -> UserContextDataType -> Bool
$c/= :: UserContextDataType -> UserContextDataType -> Bool
== :: UserContextDataType -> UserContextDataType -> Bool
$c== :: UserContextDataType -> UserContextDataType -> Bool
Prelude.Eq, ReadPrec [UserContextDataType]
ReadPrec UserContextDataType
Int -> ReadS UserContextDataType
ReadS [UserContextDataType]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UserContextDataType]
$creadListPrec :: ReadPrec [UserContextDataType]
readPrec :: ReadPrec UserContextDataType
$creadPrec :: ReadPrec UserContextDataType
readList :: ReadS [UserContextDataType]
$creadList :: ReadS [UserContextDataType]
readsPrec :: Int -> ReadS UserContextDataType
$creadsPrec :: Int -> ReadS UserContextDataType
Prelude.Read, Int -> UserContextDataType -> ShowS
[UserContextDataType] -> ShowS
UserContextDataType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UserContextDataType] -> ShowS
$cshowList :: [UserContextDataType] -> ShowS
show :: UserContextDataType -> String
$cshow :: UserContextDataType -> String
showsPrec :: Int -> UserContextDataType -> ShowS
$cshowsPrec :: Int -> UserContextDataType -> ShowS
Prelude.Show, forall x. Rep UserContextDataType x -> UserContextDataType
forall x. UserContextDataType -> Rep UserContextDataType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UserContextDataType x -> UserContextDataType
$cfrom :: forall x. UserContextDataType -> Rep UserContextDataType x
Prelude.Generic)

-- |
-- Create a value of 'UserContextDataType' 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:
--
-- 'encodedData', 'userContextDataType_encodedData' - Encoded device-fingerprint details that your app collected with the
-- Amazon Cognito context data collection library. For more information,
-- see
-- <https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pool-settings-adaptive-authentication.html#user-pool-settings-adaptive-authentication-device-fingerprint Adding user device and session data to API requests>.
--
-- 'ipAddress', 'userContextDataType_ipAddress' - The source IP address of your user\'s device.
newUserContextDataType ::
  UserContextDataType
newUserContextDataType :: UserContextDataType
newUserContextDataType =
  UserContextDataType'
    { $sel:encodedData:UserContextDataType' :: Maybe Text
encodedData = forall a. Maybe a
Prelude.Nothing,
      $sel:ipAddress:UserContextDataType' :: Maybe Text
ipAddress = forall a. Maybe a
Prelude.Nothing
    }

-- | Encoded device-fingerprint details that your app collected with the
-- Amazon Cognito context data collection library. For more information,
-- see
-- <https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pool-settings-adaptive-authentication.html#user-pool-settings-adaptive-authentication-device-fingerprint Adding user device and session data to API requests>.
userContextDataType_encodedData :: Lens.Lens' UserContextDataType (Prelude.Maybe Prelude.Text)
userContextDataType_encodedData :: Lens' UserContextDataType (Maybe Text)
userContextDataType_encodedData = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UserContextDataType' {Maybe Text
encodedData :: Maybe Text
$sel:encodedData:UserContextDataType' :: UserContextDataType -> Maybe Text
encodedData} -> Maybe Text
encodedData) (\s :: UserContextDataType
s@UserContextDataType' {} Maybe Text
a -> UserContextDataType
s {$sel:encodedData:UserContextDataType' :: Maybe Text
encodedData = Maybe Text
a} :: UserContextDataType)

-- | The source IP address of your user\'s device.
userContextDataType_ipAddress :: Lens.Lens' UserContextDataType (Prelude.Maybe Prelude.Text)
userContextDataType_ipAddress :: Lens' UserContextDataType (Maybe Text)
userContextDataType_ipAddress = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UserContextDataType' {Maybe Text
ipAddress :: Maybe Text
$sel:ipAddress:UserContextDataType' :: UserContextDataType -> Maybe Text
ipAddress} -> Maybe Text
ipAddress) (\s :: UserContextDataType
s@UserContextDataType' {} Maybe Text
a -> UserContextDataType
s {$sel:ipAddress:UserContextDataType' :: Maybe Text
ipAddress = Maybe Text
a} :: UserContextDataType)

instance Prelude.Hashable UserContextDataType where
  hashWithSalt :: Int -> UserContextDataType -> Int
hashWithSalt Int
_salt UserContextDataType' {Maybe Text
ipAddress :: Maybe Text
encodedData :: Maybe Text
$sel:ipAddress:UserContextDataType' :: UserContextDataType -> Maybe Text
$sel:encodedData:UserContextDataType' :: UserContextDataType -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
encodedData
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
ipAddress

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

instance Data.ToJSON UserContextDataType where
  toJSON :: UserContextDataType -> Value
toJSON UserContextDataType' {Maybe Text
ipAddress :: Maybe Text
encodedData :: Maybe Text
$sel:ipAddress:UserContextDataType' :: UserContextDataType -> Maybe Text
$sel:encodedData:UserContextDataType' :: UserContextDataType -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"EncodedData" 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
encodedData,
            (Key
"IpAddress" 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
ipAddress
          ]
      )