{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.PutProfileObject
-- 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)
--
-- Adds additional objects to customer profiles of a given ObjectType.
--
-- When adding a specific profile object, like a Contact Trace Record
-- (CTR), an inferred profile can get created if it is not mapped to an
-- existing profile. The resulting profile will only have a phone number
-- populated in the standard ProfileObject. Any additional CTRs with the
-- same phone number will be mapped to the same inferred profile.
--
-- When a ProfileObject is created and if a ProfileObjectType already
-- exists for the ProfileObject, it will provide data to a standard profile
-- depending on the ProfileObjectType definition.
--
-- PutProfileObject needs an ObjectType, which can be created using
-- PutProfileObjectType.
module Amazonka.CustomerProfiles.PutProfileObject
  ( -- * Creating a Request
    PutProfileObject (..),
    newPutProfileObject,

    -- * Request Lenses
    putProfileObject_objectTypeName,
    putProfileObject_object,
    putProfileObject_domainName,

    -- * Destructuring the Response
    PutProfileObjectResponse (..),
    newPutProfileObjectResponse,

    -- * Response Lenses
    putProfileObjectResponse_profileObjectUniqueKey,
    putProfileObjectResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.CustomerProfiles.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newPutProfileObject' smart constructor.
data PutProfileObject = PutProfileObject'
  { -- | The name of the profile object type.
    PutProfileObject -> Text
objectTypeName :: Prelude.Text,
    -- | A string that is serialized from a JSON object.
    PutProfileObject -> Text
object' :: Prelude.Text,
    -- | The unique name of the domain.
    PutProfileObject -> Text
domainName :: Prelude.Text
  }
  deriving (PutProfileObject -> PutProfileObject -> Bool
(PutProfileObject -> PutProfileObject -> Bool)
-> (PutProfileObject -> PutProfileObject -> Bool)
-> Eq PutProfileObject
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutProfileObject -> PutProfileObject -> Bool
$c/= :: PutProfileObject -> PutProfileObject -> Bool
== :: PutProfileObject -> PutProfileObject -> Bool
$c== :: PutProfileObject -> PutProfileObject -> Bool
Prelude.Eq, ReadPrec [PutProfileObject]
ReadPrec PutProfileObject
Int -> ReadS PutProfileObject
ReadS [PutProfileObject]
(Int -> ReadS PutProfileObject)
-> ReadS [PutProfileObject]
-> ReadPrec PutProfileObject
-> ReadPrec [PutProfileObject]
-> Read PutProfileObject
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutProfileObject]
$creadListPrec :: ReadPrec [PutProfileObject]
readPrec :: ReadPrec PutProfileObject
$creadPrec :: ReadPrec PutProfileObject
readList :: ReadS [PutProfileObject]
$creadList :: ReadS [PutProfileObject]
readsPrec :: Int -> ReadS PutProfileObject
$creadsPrec :: Int -> ReadS PutProfileObject
Prelude.Read, Int -> PutProfileObject -> ShowS
[PutProfileObject] -> ShowS
PutProfileObject -> String
(Int -> PutProfileObject -> ShowS)
-> (PutProfileObject -> String)
-> ([PutProfileObject] -> ShowS)
-> Show PutProfileObject
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutProfileObject] -> ShowS
$cshowList :: [PutProfileObject] -> ShowS
show :: PutProfileObject -> String
$cshow :: PutProfileObject -> String
showsPrec :: Int -> PutProfileObject -> ShowS
$cshowsPrec :: Int -> PutProfileObject -> ShowS
Prelude.Show, (forall x. PutProfileObject -> Rep PutProfileObject x)
-> (forall x. Rep PutProfileObject x -> PutProfileObject)
-> Generic PutProfileObject
forall x. Rep PutProfileObject x -> PutProfileObject
forall x. PutProfileObject -> Rep PutProfileObject x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutProfileObject x -> PutProfileObject
$cfrom :: forall x. PutProfileObject -> Rep PutProfileObject x
Prelude.Generic)

-- |
-- Create a value of 'PutProfileObject' 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:
--
-- 'objectTypeName', 'putProfileObject_objectTypeName' - The name of the profile object type.
--
-- 'object'', 'putProfileObject_object' - A string that is serialized from a JSON object.
--
-- 'domainName', 'putProfileObject_domainName' - The unique name of the domain.
newPutProfileObject ::
  -- | 'objectTypeName'
  Prelude.Text ->
  -- | 'object''
  Prelude.Text ->
  -- | 'domainName'
  Prelude.Text ->
  PutProfileObject
newPutProfileObject :: Text -> Text -> Text -> PutProfileObject
newPutProfileObject
  Text
pObjectTypeName_
  Text
pObject_
  Text
pDomainName_ =
    PutProfileObject' :: Text -> Text -> Text -> PutProfileObject
PutProfileObject'
      { $sel:objectTypeName:PutProfileObject' :: Text
objectTypeName =
          Text
pObjectTypeName_,
        $sel:object':PutProfileObject' :: Text
object' = Text
pObject_,
        $sel:domainName:PutProfileObject' :: Text
domainName = Text
pDomainName_
      }

-- | The name of the profile object type.
putProfileObject_objectTypeName :: Lens.Lens' PutProfileObject Prelude.Text
putProfileObject_objectTypeName :: (Text -> f Text) -> PutProfileObject -> f PutProfileObject
putProfileObject_objectTypeName = (PutProfileObject -> Text)
-> (PutProfileObject -> Text -> PutProfileObject)
-> Lens PutProfileObject PutProfileObject Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutProfileObject' {Text
objectTypeName :: Text
$sel:objectTypeName:PutProfileObject' :: PutProfileObject -> Text
objectTypeName} -> Text
objectTypeName) (\s :: PutProfileObject
s@PutProfileObject' {} Text
a -> PutProfileObject
s {$sel:objectTypeName:PutProfileObject' :: Text
objectTypeName = Text
a} :: PutProfileObject)

-- | A string that is serialized from a JSON object.
putProfileObject_object :: Lens.Lens' PutProfileObject Prelude.Text
putProfileObject_object :: (Text -> f Text) -> PutProfileObject -> f PutProfileObject
putProfileObject_object = (PutProfileObject -> Text)
-> (PutProfileObject -> Text -> PutProfileObject)
-> Lens PutProfileObject PutProfileObject Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutProfileObject' {Text
object' :: Text
$sel:object':PutProfileObject' :: PutProfileObject -> Text
object'} -> Text
object') (\s :: PutProfileObject
s@PutProfileObject' {} Text
a -> PutProfileObject
s {$sel:object':PutProfileObject' :: Text
object' = Text
a} :: PutProfileObject)

-- | The unique name of the domain.
putProfileObject_domainName :: Lens.Lens' PutProfileObject Prelude.Text
putProfileObject_domainName :: (Text -> f Text) -> PutProfileObject -> f PutProfileObject
putProfileObject_domainName = (PutProfileObject -> Text)
-> (PutProfileObject -> Text -> PutProfileObject)
-> Lens PutProfileObject PutProfileObject Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutProfileObject' {Text
domainName :: Text
$sel:domainName:PutProfileObject' :: PutProfileObject -> Text
domainName} -> Text
domainName) (\s :: PutProfileObject
s@PutProfileObject' {} Text
a -> PutProfileObject
s {$sel:domainName:PutProfileObject' :: Text
domainName = Text
a} :: PutProfileObject)

instance Core.AWSRequest PutProfileObject where
  type
    AWSResponse PutProfileObject =
      PutProfileObjectResponse
  request :: PutProfileObject -> Request PutProfileObject
request = Service -> PutProfileObject -> Request PutProfileObject
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutProfileObject
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutProfileObject)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse PutProfileObject))
-> Logger
-> Service
-> Proxy PutProfileObject
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutProfileObject)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Int -> PutProfileObjectResponse
PutProfileObjectResponse'
            (Maybe Text -> Int -> PutProfileObjectResponse)
-> Either String (Maybe Text)
-> Either String (Int -> PutProfileObjectResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"ProfileObjectUniqueKey")
            Either String (Int -> PutProfileObjectResponse)
-> Either String Int -> Either String PutProfileObjectResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable PutProfileObject

instance Prelude.NFData PutProfileObject

instance Core.ToHeaders PutProfileObject where
  toHeaders :: PutProfileObject -> ResponseHeaders
toHeaders =
    ResponseHeaders -> PutProfileObject -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON PutProfileObject where
  toJSON :: PutProfileObject -> Value
toJSON PutProfileObject' {Text
domainName :: Text
object' :: Text
objectTypeName :: Text
$sel:domainName:PutProfileObject' :: PutProfileObject -> Text
$sel:object':PutProfileObject' :: PutProfileObject -> Text
$sel:objectTypeName:PutProfileObject' :: PutProfileObject -> 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
"ObjectTypeName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
objectTypeName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Object" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
object')
          ]
      )

instance Core.ToPath PutProfileObject where
  toPath :: PutProfileObject -> ByteString
toPath PutProfileObject' {Text
domainName :: Text
object' :: Text
objectTypeName :: Text
$sel:domainName:PutProfileObject' :: PutProfileObject -> Text
$sel:object':PutProfileObject' :: PutProfileObject -> Text
$sel:objectTypeName:PutProfileObject' :: PutProfileObject -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/domains/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
domainName,
        ByteString
"/profiles/objects"
      ]

instance Core.ToQuery PutProfileObject where
  toQuery :: PutProfileObject -> QueryString
toQuery = QueryString -> PutProfileObject -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newPutProfileObjectResponse' smart constructor.
data PutProfileObjectResponse = PutProfileObjectResponse'
  { -- | The unique identifier of the profile object generated by the service.
    PutProfileObjectResponse -> Maybe Text
profileObjectUniqueKey :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    PutProfileObjectResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (PutProfileObjectResponse -> PutProfileObjectResponse -> Bool
(PutProfileObjectResponse -> PutProfileObjectResponse -> Bool)
-> (PutProfileObjectResponse -> PutProfileObjectResponse -> Bool)
-> Eq PutProfileObjectResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutProfileObjectResponse -> PutProfileObjectResponse -> Bool
$c/= :: PutProfileObjectResponse -> PutProfileObjectResponse -> Bool
== :: PutProfileObjectResponse -> PutProfileObjectResponse -> Bool
$c== :: PutProfileObjectResponse -> PutProfileObjectResponse -> Bool
Prelude.Eq, ReadPrec [PutProfileObjectResponse]
ReadPrec PutProfileObjectResponse
Int -> ReadS PutProfileObjectResponse
ReadS [PutProfileObjectResponse]
(Int -> ReadS PutProfileObjectResponse)
-> ReadS [PutProfileObjectResponse]
-> ReadPrec PutProfileObjectResponse
-> ReadPrec [PutProfileObjectResponse]
-> Read PutProfileObjectResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutProfileObjectResponse]
$creadListPrec :: ReadPrec [PutProfileObjectResponse]
readPrec :: ReadPrec PutProfileObjectResponse
$creadPrec :: ReadPrec PutProfileObjectResponse
readList :: ReadS [PutProfileObjectResponse]
$creadList :: ReadS [PutProfileObjectResponse]
readsPrec :: Int -> ReadS PutProfileObjectResponse
$creadsPrec :: Int -> ReadS PutProfileObjectResponse
Prelude.Read, Int -> PutProfileObjectResponse -> ShowS
[PutProfileObjectResponse] -> ShowS
PutProfileObjectResponse -> String
(Int -> PutProfileObjectResponse -> ShowS)
-> (PutProfileObjectResponse -> String)
-> ([PutProfileObjectResponse] -> ShowS)
-> Show PutProfileObjectResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutProfileObjectResponse] -> ShowS
$cshowList :: [PutProfileObjectResponse] -> ShowS
show :: PutProfileObjectResponse -> String
$cshow :: PutProfileObjectResponse -> String
showsPrec :: Int -> PutProfileObjectResponse -> ShowS
$cshowsPrec :: Int -> PutProfileObjectResponse -> ShowS
Prelude.Show, (forall x.
 PutProfileObjectResponse -> Rep PutProfileObjectResponse x)
-> (forall x.
    Rep PutProfileObjectResponse x -> PutProfileObjectResponse)
-> Generic PutProfileObjectResponse
forall x.
Rep PutProfileObjectResponse x -> PutProfileObjectResponse
forall x.
PutProfileObjectResponse -> Rep PutProfileObjectResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PutProfileObjectResponse x -> PutProfileObjectResponse
$cfrom :: forall x.
PutProfileObjectResponse -> Rep PutProfileObjectResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutProfileObjectResponse' 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:
--
-- 'profileObjectUniqueKey', 'putProfileObjectResponse_profileObjectUniqueKey' - The unique identifier of the profile object generated by the service.
--
-- 'httpStatus', 'putProfileObjectResponse_httpStatus' - The response's http status code.
newPutProfileObjectResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutProfileObjectResponse
newPutProfileObjectResponse :: Int -> PutProfileObjectResponse
newPutProfileObjectResponse Int
pHttpStatus_ =
  PutProfileObjectResponse' :: Maybe Text -> Int -> PutProfileObjectResponse
PutProfileObjectResponse'
    { $sel:profileObjectUniqueKey:PutProfileObjectResponse' :: Maybe Text
profileObjectUniqueKey =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PutProfileObjectResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The unique identifier of the profile object generated by the service.
putProfileObjectResponse_profileObjectUniqueKey :: Lens.Lens' PutProfileObjectResponse (Prelude.Maybe Prelude.Text)
putProfileObjectResponse_profileObjectUniqueKey :: (Maybe Text -> f (Maybe Text))
-> PutProfileObjectResponse -> f PutProfileObjectResponse
putProfileObjectResponse_profileObjectUniqueKey = (PutProfileObjectResponse -> Maybe Text)
-> (PutProfileObjectResponse
    -> Maybe Text -> PutProfileObjectResponse)
-> Lens
     PutProfileObjectResponse
     PutProfileObjectResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutProfileObjectResponse' {Maybe Text
profileObjectUniqueKey :: Maybe Text
$sel:profileObjectUniqueKey:PutProfileObjectResponse' :: PutProfileObjectResponse -> Maybe Text
profileObjectUniqueKey} -> Maybe Text
profileObjectUniqueKey) (\s :: PutProfileObjectResponse
s@PutProfileObjectResponse' {} Maybe Text
a -> PutProfileObjectResponse
s {$sel:profileObjectUniqueKey:PutProfileObjectResponse' :: Maybe Text
profileObjectUniqueKey = Maybe Text
a} :: PutProfileObjectResponse)

-- | The response's http status code.
putProfileObjectResponse_httpStatus :: Lens.Lens' PutProfileObjectResponse Prelude.Int
putProfileObjectResponse_httpStatus :: (Int -> f Int)
-> PutProfileObjectResponse -> f PutProfileObjectResponse
putProfileObjectResponse_httpStatus = (PutProfileObjectResponse -> Int)
-> (PutProfileObjectResponse -> Int -> PutProfileObjectResponse)
-> Lens PutProfileObjectResponse PutProfileObjectResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutProfileObjectResponse' {Int
httpStatus :: Int
$sel:httpStatus:PutProfileObjectResponse' :: PutProfileObjectResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: PutProfileObjectResponse
s@PutProfileObjectResponse' {} Int
a -> PutProfileObjectResponse
s {$sel:httpStatus:PutProfileObjectResponse' :: Int
httpStatus = Int
a} :: PutProfileObjectResponse)

instance Prelude.NFData PutProfileObjectResponse