{-# 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.FraudDetector.Types.Entity
-- 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.FraudDetector.Types.Entity where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The entity details.
--
-- /See:/ 'newEntity' smart constructor.
data Entity = Entity'
  { -- | The entity type.
    Entity -> Text
entityType :: Prelude.Text,
    -- | The entity ID. If you do not know the @entityId@, you can pass
    -- @unknown@, which is areserved string literal.
    Entity -> Text
entityId :: Prelude.Text
  }
  deriving (Entity -> Entity -> Bool
(Entity -> Entity -> Bool)
-> (Entity -> Entity -> Bool) -> Eq Entity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Entity -> Entity -> Bool
$c/= :: Entity -> Entity -> Bool
== :: Entity -> Entity -> Bool
$c== :: Entity -> Entity -> Bool
Prelude.Eq, Int -> Entity -> ShowS
[Entity] -> ShowS
Entity -> String
(Int -> Entity -> ShowS)
-> (Entity -> String) -> ([Entity] -> ShowS) -> Show Entity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Entity] -> ShowS
$cshowList :: [Entity] -> ShowS
show :: Entity -> String
$cshow :: Entity -> String
showsPrec :: Int -> Entity -> ShowS
$cshowsPrec :: Int -> Entity -> ShowS
Prelude.Show, (forall x. Entity -> Rep Entity x)
-> (forall x. Rep Entity x -> Entity) -> Generic Entity
forall x. Rep Entity x -> Entity
forall x. Entity -> Rep Entity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Entity x -> Entity
$cfrom :: forall x. Entity -> Rep Entity x
Prelude.Generic)

-- |
-- Create a value of 'Entity' 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:
--
-- 'entityType', 'entity_entityType' - The entity type.
--
-- 'entityId', 'entity_entityId' - The entity ID. If you do not know the @entityId@, you can pass
-- @unknown@, which is areserved string literal.
newEntity ::
  -- | 'entityType'
  Prelude.Text ->
  -- | 'entityId'
  Prelude.Text ->
  Entity
newEntity :: Text -> Text -> Entity
newEntity Text
pEntityType_ Text
pEntityId_ =
  Entity' :: Text -> Text -> Entity
Entity'
    { $sel:entityType:Entity' :: Text
entityType = Text
pEntityType_,
      $sel:entityId:Entity' :: Text
entityId = Text
pEntityId_
    }

-- | The entity type.
entity_entityType :: Lens.Lens' Entity Prelude.Text
entity_entityType :: (Text -> f Text) -> Entity -> f Entity
entity_entityType = (Entity -> Text)
-> (Entity -> Text -> Entity) -> Lens Entity Entity Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entity' {Text
entityType :: Text
$sel:entityType:Entity' :: Entity -> Text
entityType} -> Text
entityType) (\s :: Entity
s@Entity' {} Text
a -> Entity
s {$sel:entityType:Entity' :: Text
entityType = Text
a} :: Entity)

-- | The entity ID. If you do not know the @entityId@, you can pass
-- @unknown@, which is areserved string literal.
entity_entityId :: Lens.Lens' Entity Prelude.Text
entity_entityId :: (Text -> f Text) -> Entity -> f Entity
entity_entityId = (Entity -> Text)
-> (Entity -> Text -> Entity) -> Lens Entity Entity Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entity' {Text
entityId :: Text
$sel:entityId:Entity' :: Entity -> Text
entityId} -> Text
entityId) (\s :: Entity
s@Entity' {} Text
a -> Entity
s {$sel:entityId:Entity' :: Text
entityId = Text
a} :: Entity)

instance Core.FromJSON Entity where
  parseJSON :: Value -> Parser Entity
parseJSON =
    String -> (Object -> Parser Entity) -> Value -> Parser Entity
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Entity"
      ( \Object
x ->
          Text -> Text -> Entity
Entity'
            (Text -> Text -> Entity) -> Parser Text -> Parser (Text -> Entity)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"entityType")
            Parser (Text -> Entity) -> Parser Text -> Parser Entity
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"entityId")
      )

instance Prelude.Hashable Entity

instance Prelude.NFData Entity

instance Core.ToJSON Entity where
  toJSON :: Entity -> Value
toJSON Entity' {Text
entityId :: Text
entityType :: Text
$sel:entityId:Entity' :: Entity -> Text
$sel:entityType:Entity' :: Entity -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"entityType" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
entityType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"entityId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
entityId)
          ]
      )