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

import Amazonka.CognitoIdentityProvider.Types.HttpHeader
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 data containing device fingerprinting details, collected using
    -- the Amazon Cognito context data collection library.
    ContextDataType -> Maybe Text
encodedData :: Prelude.Maybe Prelude.Text,
    -- | Source IP address of your user.
    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
(ContextDataType -> ContextDataType -> Bool)
-> (ContextDataType -> ContextDataType -> Bool)
-> Eq ContextDataType
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]
(Int -> ReadS ContextDataType)
-> ReadS [ContextDataType]
-> ReadPrec ContextDataType
-> ReadPrec [ContextDataType]
-> Read 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
(Int -> ContextDataType -> ShowS)
-> (ContextDataType -> String)
-> ([ContextDataType] -> ShowS)
-> Show ContextDataType
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. ContextDataType -> Rep ContextDataType x)
-> (forall x. Rep ContextDataType x -> ContextDataType)
-> Generic ContextDataType
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 data containing device fingerprinting details, collected using
-- the Amazon Cognito context data collection library.
--
-- 'ipAddress', 'contextDataType_ipAddress' - Source IP address of your user.
--
-- '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' :: Maybe Text
-> Text -> Text -> Text -> [HttpHeader] -> ContextDataType
ContextDataType'
      { $sel:encodedData:ContextDataType' :: Maybe Text
encodedData = Maybe Text
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 = [HttpHeader]
forall a. Monoid a => a
Prelude.mempty
      }

-- | Encoded data containing device fingerprinting details, collected using
-- the Amazon Cognito context data collection library.
contextDataType_encodedData :: Lens.Lens' ContextDataType (Prelude.Maybe Prelude.Text)
contextDataType_encodedData :: (Maybe Text -> f (Maybe Text))
-> ContextDataType -> f ContextDataType
contextDataType_encodedData = (ContextDataType -> Maybe Text)
-> (ContextDataType -> Maybe Text -> ContextDataType)
-> Lens ContextDataType ContextDataType (Maybe Text) (Maybe Text)
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)

-- | Source IP address of your user.
contextDataType_ipAddress :: Lens.Lens' ContextDataType Prelude.Text
contextDataType_ipAddress :: (Text -> f Text) -> ContextDataType -> f ContextDataType
contextDataType_ipAddress = (ContextDataType -> Text)
-> (ContextDataType -> Text -> ContextDataType)
-> Lens ContextDataType ContextDataType Text Text
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 :: (Text -> f Text) -> ContextDataType -> f ContextDataType
contextDataType_serverName = (ContextDataType -> Text)
-> (ContextDataType -> Text -> ContextDataType)
-> Lens ContextDataType ContextDataType Text Text
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 :: (Text -> f Text) -> ContextDataType -> f ContextDataType
contextDataType_serverPath = (ContextDataType -> Text)
-> (ContextDataType -> Text -> ContextDataType)
-> Lens ContextDataType ContextDataType Text Text
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 :: ([HttpHeader] -> f [HttpHeader])
-> ContextDataType -> f ContextDataType
contextDataType_httpHeaders = (ContextDataType -> [HttpHeader])
-> (ContextDataType -> [HttpHeader] -> ContextDataType)
-> Lens ContextDataType ContextDataType [HttpHeader] [HttpHeader]
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) (([HttpHeader] -> f [HttpHeader])
 -> ContextDataType -> f ContextDataType)
-> (([HttpHeader] -> f [HttpHeader])
    -> [HttpHeader] -> f [HttpHeader])
-> ([HttpHeader] -> f [HttpHeader])
-> ContextDataType
-> f ContextDataType
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([HttpHeader] -> f [HttpHeader]) -> [HttpHeader] -> f [HttpHeader]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.Hashable ContextDataType

instance Prelude.NFData ContextDataType

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"EncodedData" 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
encodedData,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"IpAddress" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
ipAddress),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ServerName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
serverName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ServerPath" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
serverPath),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"HttpHeaders" Text -> [HttpHeader] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [HttpHeader]
httpHeaders)
          ]
      )