{-# 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.CustomerProfiles.Types.ObjectTypeKey
-- 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.CustomerProfiles.Types.ObjectTypeKey where

import qualified Amazonka.Core as Core
import Amazonka.CustomerProfiles.Types.StandardIdentifier
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that defines the Key element of a ProfileObject. A Key is a
-- special element that can be used to search for a customer profile.
--
-- /See:/ 'newObjectTypeKey' smart constructor.
data ObjectTypeKey = ObjectTypeKey'
  { -- | The reference for the key name of the fields map.
    ObjectTypeKey -> Maybe [Text]
fieldNames :: Prelude.Maybe [Prelude.Text],
    -- | The types of keys that a ProfileObject can have. Each ProfileObject can
    -- have only 1 UNIQUE key but multiple PROFILE keys. PROFILE, ASSET or CASE
    -- means that this key can be used to tie an object to a PROFILE, ASSET or
    -- CASE respectively. UNIQUE means that it can be used to uniquely identify
    -- an object. If a key a is marked as SECONDARY, it will be used to search
    -- for profiles after all other PROFILE keys have been searched. A
    -- LOOKUP_ONLY key is only used to match a profile but is not persisted to
    -- be used for searching of the profile. A NEW_ONLY key is only used if the
    -- profile does not already exist before the object is ingested, otherwise
    -- it is only used for matching objects to profiles.
    ObjectTypeKey -> Maybe [StandardIdentifier]
standardIdentifiers :: Prelude.Maybe [StandardIdentifier]
  }
  deriving (ObjectTypeKey -> ObjectTypeKey -> Bool
(ObjectTypeKey -> ObjectTypeKey -> Bool)
-> (ObjectTypeKey -> ObjectTypeKey -> Bool) -> Eq ObjectTypeKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ObjectTypeKey -> ObjectTypeKey -> Bool
$c/= :: ObjectTypeKey -> ObjectTypeKey -> Bool
== :: ObjectTypeKey -> ObjectTypeKey -> Bool
$c== :: ObjectTypeKey -> ObjectTypeKey -> Bool
Prelude.Eq, ReadPrec [ObjectTypeKey]
ReadPrec ObjectTypeKey
Int -> ReadS ObjectTypeKey
ReadS [ObjectTypeKey]
(Int -> ReadS ObjectTypeKey)
-> ReadS [ObjectTypeKey]
-> ReadPrec ObjectTypeKey
-> ReadPrec [ObjectTypeKey]
-> Read ObjectTypeKey
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ObjectTypeKey]
$creadListPrec :: ReadPrec [ObjectTypeKey]
readPrec :: ReadPrec ObjectTypeKey
$creadPrec :: ReadPrec ObjectTypeKey
readList :: ReadS [ObjectTypeKey]
$creadList :: ReadS [ObjectTypeKey]
readsPrec :: Int -> ReadS ObjectTypeKey
$creadsPrec :: Int -> ReadS ObjectTypeKey
Prelude.Read, Int -> ObjectTypeKey -> ShowS
[ObjectTypeKey] -> ShowS
ObjectTypeKey -> String
(Int -> ObjectTypeKey -> ShowS)
-> (ObjectTypeKey -> String)
-> ([ObjectTypeKey] -> ShowS)
-> Show ObjectTypeKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ObjectTypeKey] -> ShowS
$cshowList :: [ObjectTypeKey] -> ShowS
show :: ObjectTypeKey -> String
$cshow :: ObjectTypeKey -> String
showsPrec :: Int -> ObjectTypeKey -> ShowS
$cshowsPrec :: Int -> ObjectTypeKey -> ShowS
Prelude.Show, (forall x. ObjectTypeKey -> Rep ObjectTypeKey x)
-> (forall x. Rep ObjectTypeKey x -> ObjectTypeKey)
-> Generic ObjectTypeKey
forall x. Rep ObjectTypeKey x -> ObjectTypeKey
forall x. ObjectTypeKey -> Rep ObjectTypeKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ObjectTypeKey x -> ObjectTypeKey
$cfrom :: forall x. ObjectTypeKey -> Rep ObjectTypeKey x
Prelude.Generic)

-- |
-- Create a value of 'ObjectTypeKey' 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:
--
-- 'fieldNames', 'objectTypeKey_fieldNames' - The reference for the key name of the fields map.
--
-- 'standardIdentifiers', 'objectTypeKey_standardIdentifiers' - The types of keys that a ProfileObject can have. Each ProfileObject can
-- have only 1 UNIQUE key but multiple PROFILE keys. PROFILE, ASSET or CASE
-- means that this key can be used to tie an object to a PROFILE, ASSET or
-- CASE respectively. UNIQUE means that it can be used to uniquely identify
-- an object. If a key a is marked as SECONDARY, it will be used to search
-- for profiles after all other PROFILE keys have been searched. A
-- LOOKUP_ONLY key is only used to match a profile but is not persisted to
-- be used for searching of the profile. A NEW_ONLY key is only used if the
-- profile does not already exist before the object is ingested, otherwise
-- it is only used for matching objects to profiles.
newObjectTypeKey ::
  ObjectTypeKey
newObjectTypeKey :: ObjectTypeKey
newObjectTypeKey =
  ObjectTypeKey' :: Maybe [Text] -> Maybe [StandardIdentifier] -> ObjectTypeKey
ObjectTypeKey'
    { $sel:fieldNames:ObjectTypeKey' :: Maybe [Text]
fieldNames = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:standardIdentifiers:ObjectTypeKey' :: Maybe [StandardIdentifier]
standardIdentifiers = Maybe [StandardIdentifier]
forall a. Maybe a
Prelude.Nothing
    }

-- | The reference for the key name of the fields map.
objectTypeKey_fieldNames :: Lens.Lens' ObjectTypeKey (Prelude.Maybe [Prelude.Text])
objectTypeKey_fieldNames :: (Maybe [Text] -> f (Maybe [Text]))
-> ObjectTypeKey -> f ObjectTypeKey
objectTypeKey_fieldNames = (ObjectTypeKey -> Maybe [Text])
-> (ObjectTypeKey -> Maybe [Text] -> ObjectTypeKey)
-> Lens ObjectTypeKey ObjectTypeKey (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ObjectTypeKey' {Maybe [Text]
fieldNames :: Maybe [Text]
$sel:fieldNames:ObjectTypeKey' :: ObjectTypeKey -> Maybe [Text]
fieldNames} -> Maybe [Text]
fieldNames) (\s :: ObjectTypeKey
s@ObjectTypeKey' {} Maybe [Text]
a -> ObjectTypeKey
s {$sel:fieldNames:ObjectTypeKey' :: Maybe [Text]
fieldNames = Maybe [Text]
a} :: ObjectTypeKey) ((Maybe [Text] -> f (Maybe [Text]))
 -> ObjectTypeKey -> f ObjectTypeKey)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> ObjectTypeKey
-> f ObjectTypeKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The types of keys that a ProfileObject can have. Each ProfileObject can
-- have only 1 UNIQUE key but multiple PROFILE keys. PROFILE, ASSET or CASE
-- means that this key can be used to tie an object to a PROFILE, ASSET or
-- CASE respectively. UNIQUE means that it can be used to uniquely identify
-- an object. If a key a is marked as SECONDARY, it will be used to search
-- for profiles after all other PROFILE keys have been searched. A
-- LOOKUP_ONLY key is only used to match a profile but is not persisted to
-- be used for searching of the profile. A NEW_ONLY key is only used if the
-- profile does not already exist before the object is ingested, otherwise
-- it is only used for matching objects to profiles.
objectTypeKey_standardIdentifiers :: Lens.Lens' ObjectTypeKey (Prelude.Maybe [StandardIdentifier])
objectTypeKey_standardIdentifiers :: (Maybe [StandardIdentifier] -> f (Maybe [StandardIdentifier]))
-> ObjectTypeKey -> f ObjectTypeKey
objectTypeKey_standardIdentifiers = (ObjectTypeKey -> Maybe [StandardIdentifier])
-> (ObjectTypeKey -> Maybe [StandardIdentifier] -> ObjectTypeKey)
-> Lens
     ObjectTypeKey
     ObjectTypeKey
     (Maybe [StandardIdentifier])
     (Maybe [StandardIdentifier])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ObjectTypeKey' {Maybe [StandardIdentifier]
standardIdentifiers :: Maybe [StandardIdentifier]
$sel:standardIdentifiers:ObjectTypeKey' :: ObjectTypeKey -> Maybe [StandardIdentifier]
standardIdentifiers} -> Maybe [StandardIdentifier]
standardIdentifiers) (\s :: ObjectTypeKey
s@ObjectTypeKey' {} Maybe [StandardIdentifier]
a -> ObjectTypeKey
s {$sel:standardIdentifiers:ObjectTypeKey' :: Maybe [StandardIdentifier]
standardIdentifiers = Maybe [StandardIdentifier]
a} :: ObjectTypeKey) ((Maybe [StandardIdentifier] -> f (Maybe [StandardIdentifier]))
 -> ObjectTypeKey -> f ObjectTypeKey)
-> ((Maybe [StandardIdentifier] -> f (Maybe [StandardIdentifier]))
    -> Maybe [StandardIdentifier] -> f (Maybe [StandardIdentifier]))
-> (Maybe [StandardIdentifier] -> f (Maybe [StandardIdentifier]))
-> ObjectTypeKey
-> f ObjectTypeKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [StandardIdentifier]
  [StandardIdentifier]
  [StandardIdentifier]
  [StandardIdentifier]
-> Iso
     (Maybe [StandardIdentifier])
     (Maybe [StandardIdentifier])
     (Maybe [StandardIdentifier])
     (Maybe [StandardIdentifier])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [StandardIdentifier]
  [StandardIdentifier]
  [StandardIdentifier]
  [StandardIdentifier]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON ObjectTypeKey where
  parseJSON :: Value -> Parser ObjectTypeKey
parseJSON =
    String
-> (Object -> Parser ObjectTypeKey)
-> Value
-> Parser ObjectTypeKey
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ObjectTypeKey"
      ( \Object
x ->
          Maybe [Text] -> Maybe [StandardIdentifier] -> ObjectTypeKey
ObjectTypeKey'
            (Maybe [Text] -> Maybe [StandardIdentifier] -> ObjectTypeKey)
-> Parser (Maybe [Text])
-> Parser (Maybe [StandardIdentifier] -> ObjectTypeKey)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"FieldNames" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe [StandardIdentifier] -> ObjectTypeKey)
-> Parser (Maybe [StandardIdentifier]) -> Parser ObjectTypeKey
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe (Maybe [StandardIdentifier]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"StandardIdentifiers"
                            Parser (Maybe (Maybe [StandardIdentifier]))
-> Maybe [StandardIdentifier]
-> Parser (Maybe [StandardIdentifier])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [StandardIdentifier]
forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable ObjectTypeKey

instance Prelude.NFData ObjectTypeKey

instance Core.ToJSON ObjectTypeKey where
  toJSON :: ObjectTypeKey -> Value
toJSON ObjectTypeKey' {Maybe [Text]
Maybe [StandardIdentifier]
standardIdentifiers :: Maybe [StandardIdentifier]
fieldNames :: Maybe [Text]
$sel:standardIdentifiers:ObjectTypeKey' :: ObjectTypeKey -> Maybe [StandardIdentifier]
$sel:fieldNames:ObjectTypeKey' :: ObjectTypeKey -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"FieldNames" 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]
fieldNames,
            (Text
"StandardIdentifiers" Text -> [StandardIdentifier] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([StandardIdentifier] -> Pair)
-> Maybe [StandardIdentifier] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [StandardIdentifier]
standardIdentifiers
          ]
      )