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

import Amazonka.CognitoIdentityProvider.Types.HttpHeader
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 user data type used for evaluating the risk of an unexpected
-- event by Amazon Cognito advanced security.
--
-- /See:/ 'newContextDataType' smart constructor.
data ContextDataType = ContextDataType'
  { -- | 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>.
    ContextDataType -> Maybe Text
encodedData :: Prelude.Maybe Prelude.Text,
    -- | The source IP address of your user\'s device.
    ContextDataType -> Text
ipAddress :: Prelude.Text,
    -- | Your server endpoint where this API is invoked.
    ContextDataType -> Text
serverName :: Prelude.Text,
    -- | Your server path where this API is invoked.
    ContextDataType -> Text
serverPath :: Prelude.Text,
    -- | HttpHeaders received on your server in same order.
    ContextDataType -> [HttpHeader]
httpHeaders :: [HttpHeader]
  }
  deriving (ContextDataType -> ContextDataType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ContextDataType -> ContextDataType -> Bool
$c/= :: ContextDataType -> ContextDataType -> Bool
== :: ContextDataType -> ContextDataType -> Bool
$c== :: ContextDataType -> ContextDataType -> Bool
Prelude.Eq, ReadPrec [ContextDataType]
ReadPrec ContextDataType
Int -> ReadS ContextDataType
ReadS [ContextDataType]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ContextDataType]
$creadListPrec :: ReadPrec [ContextDataType]
readPrec :: ReadPrec ContextDataType
$creadPrec :: ReadPrec ContextDataType
readList :: ReadS [ContextDataType]
$creadList :: ReadS [ContextDataType]
readsPrec :: Int -> ReadS ContextDataType
$creadsPrec :: Int -> ReadS ContextDataType
Prelude.Read, Int -> ContextDataType -> ShowS
[ContextDataType] -> ShowS
ContextDataType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ContextDataType] -> ShowS
$cshowList :: [ContextDataType] -> ShowS
show :: ContextDataType -> String
$cshow :: ContextDataType -> String
showsPrec :: Int -> ContextDataType -> ShowS
$cshowsPrec :: Int -> ContextDataType -> ShowS
Prelude.Show, forall x. Rep ContextDataType x -> ContextDataType
forall x. ContextDataType -> Rep ContextDataType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ContextDataType x -> ContextDataType
$cfrom :: forall x. ContextDataType -> Rep ContextDataType x
Prelude.Generic)

-- |
-- Create a value of 'ContextDataType' 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', 'contextDataType_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', 'contextDataType_ipAddress' - The source IP address of your user\'s device.
--
-- 'serverName', 'contextDataType_serverName' - Your server endpoint where this API is invoked.
--
-- 'serverPath', 'contextDataType_serverPath' - Your server path where this API is invoked.
--
-- 'httpHeaders', 'contextDataType_httpHeaders' - HttpHeaders received on your server in same order.
newContextDataType ::
  -- | 'ipAddress'
  Prelude.Text ->
  -- | 'serverName'
  Prelude.Text ->
  -- | 'serverPath'
  Prelude.Text ->
  ContextDataType
newContextDataType :: Text -> Text -> Text -> ContextDataType
newContextDataType
  Text
pIpAddress_
  Text
pServerName_
  Text
pServerPath_ =
    ContextDataType'
      { $sel:encodedData:ContextDataType' :: Maybe Text
encodedData = forall a. Maybe a
Prelude.Nothing,
        $sel:ipAddress:ContextDataType' :: Text
ipAddress = Text
pIpAddress_,
        $sel:serverName:ContextDataType' :: Text
serverName = Text
pServerName_,
        $sel:serverPath:ContextDataType' :: Text
serverPath = Text
pServerPath_,
        $sel:httpHeaders:ContextDataType' :: [HttpHeader]
httpHeaders = forall a. Monoid a => a
Prelude.mempty
      }

-- | 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>.
contextDataType_encodedData :: Lens.Lens' ContextDataType (Prelude.Maybe Prelude.Text)
contextDataType_encodedData :: Lens' ContextDataType (Maybe Text)
contextDataType_encodedData = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ContextDataType' {Maybe Text
encodedData :: Maybe Text
$sel:encodedData:ContextDataType' :: ContextDataType -> Maybe Text
encodedData} -> Maybe Text
encodedData) (\s :: ContextDataType
s@ContextDataType' {} Maybe Text
a -> ContextDataType
s {$sel:encodedData:ContextDataType' :: Maybe Text
encodedData = Maybe Text
a} :: ContextDataType)

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

-- | Your server endpoint where this API is invoked.
contextDataType_serverName :: Lens.Lens' ContextDataType Prelude.Text
contextDataType_serverName :: Lens' ContextDataType Text
contextDataType_serverName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ContextDataType' {Text
serverName :: Text
$sel:serverName:ContextDataType' :: ContextDataType -> Text
serverName} -> Text
serverName) (\s :: ContextDataType
s@ContextDataType' {} Text
a -> ContextDataType
s {$sel:serverName:ContextDataType' :: Text
serverName = Text
a} :: ContextDataType)

-- | Your server path where this API is invoked.
contextDataType_serverPath :: Lens.Lens' ContextDataType Prelude.Text
contextDataType_serverPath :: Lens' ContextDataType Text
contextDataType_serverPath = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ContextDataType' {Text
serverPath :: Text
$sel:serverPath:ContextDataType' :: ContextDataType -> Text
serverPath} -> Text
serverPath) (\s :: ContextDataType
s@ContextDataType' {} Text
a -> ContextDataType
s {$sel:serverPath:ContextDataType' :: Text
serverPath = Text
a} :: ContextDataType)

-- | HttpHeaders received on your server in same order.
contextDataType_httpHeaders :: Lens.Lens' ContextDataType [HttpHeader]
contextDataType_httpHeaders :: Lens' ContextDataType [HttpHeader]
contextDataType_httpHeaders = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ContextDataType' {[HttpHeader]
httpHeaders :: [HttpHeader]
$sel:httpHeaders:ContextDataType' :: ContextDataType -> [HttpHeader]
httpHeaders} -> [HttpHeader]
httpHeaders) (\s :: ContextDataType
s@ContextDataType' {} [HttpHeader]
a -> ContextDataType
s {$sel:httpHeaders:ContextDataType' :: [HttpHeader]
httpHeaders = [HttpHeader]
a} :: ContextDataType) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.Hashable ContextDataType where
  hashWithSalt :: Int -> ContextDataType -> Int
hashWithSalt Int
_salt ContextDataType' {[HttpHeader]
Maybe Text
Text
httpHeaders :: [HttpHeader]
serverPath :: Text
serverName :: Text
ipAddress :: Text
encodedData :: Maybe Text
$sel:httpHeaders:ContextDataType' :: ContextDataType -> [HttpHeader]
$sel:serverPath:ContextDataType' :: ContextDataType -> Text
$sel:serverName:ContextDataType' :: ContextDataType -> Text
$sel:ipAddress:ContextDataType' :: ContextDataType -> Text
$sel:encodedData:ContextDataType' :: ContextDataType -> 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` Text
ipAddress
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
serverName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
serverPath
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [HttpHeader]
httpHeaders

instance Prelude.NFData ContextDataType where
  rnf :: ContextDataType -> ()
rnf ContextDataType' {[HttpHeader]
Maybe Text
Text
httpHeaders :: [HttpHeader]
serverPath :: Text
serverName :: Text
ipAddress :: Text
encodedData :: Maybe Text
$sel:httpHeaders:ContextDataType' :: ContextDataType -> [HttpHeader]
$sel:serverPath:ContextDataType' :: ContextDataType -> Text
$sel:serverName:ContextDataType' :: ContextDataType -> Text
$sel:ipAddress:ContextDataType' :: ContextDataType -> Text
$sel:encodedData:ContextDataType' :: ContextDataType -> 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 Text
ipAddress
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
serverName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
serverPath
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [HttpHeader]
httpHeaders

instance Data.ToJSON ContextDataType where
  toJSON :: ContextDataType -> Value
toJSON ContextDataType' {[HttpHeader]
Maybe Text
Text
httpHeaders :: [HttpHeader]
serverPath :: Text
serverName :: Text
ipAddress :: Text
encodedData :: Maybe Text
$sel:httpHeaders:ContextDataType' :: ContextDataType -> [HttpHeader]
$sel:serverPath:ContextDataType' :: ContextDataType -> Text
$sel:serverName:ContextDataType' :: ContextDataType -> Text
$sel:ipAddress:ContextDataType' :: ContextDataType -> Text
$sel:encodedData:ContextDataType' :: ContextDataType -> 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,
            forall a. a -> Maybe a
Prelude.Just (Key
"IpAddress" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
ipAddress),
            forall a. a -> Maybe a
Prelude.Just (Key
"ServerName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
serverName),
            forall a. a -> Maybe a
Prelude.Just (Key
"ServerPath" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
serverPath),
            forall a. a -> Maybe a
Prelude.Just (Key
"HttpHeaders" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [HttpHeader]
httpHeaders)
          ]
      )