{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CustomerProfiles.Types.ObjectTypeKey where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import Amazonka.CustomerProfiles.Types.StandardIdentifier
import qualified Amazonka.Data as Data
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, CASE,
    -- or ORDER means that this key can be used to tie an object to a PROFILE,
    -- ASSET, CASE, or ORDER 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
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]
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
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. 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, CASE,
-- or ORDER means that this key can be used to tie an object to a PROFILE,
-- ASSET, CASE, or ORDER 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'
    { $sel:fieldNames:ObjectTypeKey' :: Maybe [Text]
fieldNames = forall a. Maybe a
Prelude.Nothing,
      $sel:standardIdentifiers:ObjectTypeKey' :: Maybe [StandardIdentifier]
standardIdentifiers = 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 :: Lens' ObjectTypeKey (Maybe [Text])
objectTypeKey_fieldNames = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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, CASE,
-- or ORDER means that this key can be used to tie an object to a PROFILE,
-- ASSET, CASE, or ORDER 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 :: Lens' ObjectTypeKey (Maybe [StandardIdentifier])
objectTypeKey_standardIdentifiers = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable ObjectTypeKey where
  hashWithSalt :: Int -> ObjectTypeKey -> Int
hashWithSalt Int
_salt ObjectTypeKey' {Maybe [Text]
Maybe [StandardIdentifier]
standardIdentifiers :: Maybe [StandardIdentifier]
fieldNames :: Maybe [Text]
$sel:standardIdentifiers:ObjectTypeKey' :: ObjectTypeKey -> Maybe [StandardIdentifier]
$sel:fieldNames:ObjectTypeKey' :: ObjectTypeKey -> Maybe [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
fieldNames
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [StandardIdentifier]
standardIdentifiers

instance Prelude.NFData ObjectTypeKey where
  rnf :: ObjectTypeKey -> ()
rnf ObjectTypeKey' {Maybe [Text]
Maybe [StandardIdentifier]
standardIdentifiers :: Maybe [StandardIdentifier]
fieldNames :: Maybe [Text]
$sel:standardIdentifiers:ObjectTypeKey' :: ObjectTypeKey -> Maybe [StandardIdentifier]
$sel:fieldNames:ObjectTypeKey' :: ObjectTypeKey -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
fieldNames
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [StandardIdentifier]
standardIdentifiers

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"FieldNames" 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]
fieldNames,
            (Key
"StandardIdentifiers" 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 [StandardIdentifier]
standardIdentifiers
          ]
      )