{-# 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.PersonalizeEvents.PutUsers
-- 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 one or more users to a Users dataset. For more information see
-- <https://docs.aws.amazon.com/personalize/latest/dg/importing-users.html Importing Users Incrementally>.
module Amazonka.PersonalizeEvents.PutUsers
  ( -- * Creating a Request
    PutUsers (..),
    newPutUsers,

    -- * Request Lenses
    putUsers_datasetArn,
    putUsers_users,

    -- * Destructuring the Response
    PutUsersResponse (..),
    newPutUsersResponse,
  )
where

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

-- | /See:/ 'newPutUsers' smart constructor.
data PutUsers = PutUsers'
  { -- | The Amazon Resource Name (ARN) of the Users dataset you are adding the
    -- user or users to.
    PutUsers -> Text
datasetArn :: Prelude.Text,
    -- | A list of user data.
    PutUsers -> NonEmpty User
users :: Prelude.NonEmpty User
  }
  deriving (PutUsers -> PutUsers -> Bool
(PutUsers -> PutUsers -> Bool)
-> (PutUsers -> PutUsers -> Bool) -> Eq PutUsers
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutUsers -> PutUsers -> Bool
$c/= :: PutUsers -> PutUsers -> Bool
== :: PutUsers -> PutUsers -> Bool
$c== :: PutUsers -> PutUsers -> Bool
Prelude.Eq, ReadPrec [PutUsers]
ReadPrec PutUsers
Int -> ReadS PutUsers
ReadS [PutUsers]
(Int -> ReadS PutUsers)
-> ReadS [PutUsers]
-> ReadPrec PutUsers
-> ReadPrec [PutUsers]
-> Read PutUsers
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutUsers]
$creadListPrec :: ReadPrec [PutUsers]
readPrec :: ReadPrec PutUsers
$creadPrec :: ReadPrec PutUsers
readList :: ReadS [PutUsers]
$creadList :: ReadS [PutUsers]
readsPrec :: Int -> ReadS PutUsers
$creadsPrec :: Int -> ReadS PutUsers
Prelude.Read, Int -> PutUsers -> ShowS
[PutUsers] -> ShowS
PutUsers -> String
(Int -> PutUsers -> ShowS)
-> (PutUsers -> String) -> ([PutUsers] -> ShowS) -> Show PutUsers
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutUsers] -> ShowS
$cshowList :: [PutUsers] -> ShowS
show :: PutUsers -> String
$cshow :: PutUsers -> String
showsPrec :: Int -> PutUsers -> ShowS
$cshowsPrec :: Int -> PutUsers -> ShowS
Prelude.Show, (forall x. PutUsers -> Rep PutUsers x)
-> (forall x. Rep PutUsers x -> PutUsers) -> Generic PutUsers
forall x. Rep PutUsers x -> PutUsers
forall x. PutUsers -> Rep PutUsers x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutUsers x -> PutUsers
$cfrom :: forall x. PutUsers -> Rep PutUsers x
Prelude.Generic)

-- |
-- Create a value of 'PutUsers' 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:
--
-- 'datasetArn', 'putUsers_datasetArn' - The Amazon Resource Name (ARN) of the Users dataset you are adding the
-- user or users to.
--
-- 'users', 'putUsers_users' - A list of user data.
newPutUsers ::
  -- | 'datasetArn'
  Prelude.Text ->
  -- | 'users'
  Prelude.NonEmpty User ->
  PutUsers
newPutUsers :: Text -> NonEmpty User -> PutUsers
newPutUsers Text
pDatasetArn_ NonEmpty User
pUsers_ =
  PutUsers' :: Text -> NonEmpty User -> PutUsers
PutUsers'
    { $sel:datasetArn:PutUsers' :: Text
datasetArn = Text
pDatasetArn_,
      $sel:users:PutUsers' :: NonEmpty User
users = Tagged (NonEmpty User) (Identity (NonEmpty User))
-> Tagged (NonEmpty User) (Identity (NonEmpty User))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty User) (Identity (NonEmpty User))
 -> Tagged (NonEmpty User) (Identity (NonEmpty User)))
-> NonEmpty User -> NonEmpty User
forall t b. AReview t b -> b -> t
Lens.# NonEmpty User
pUsers_
    }

-- | The Amazon Resource Name (ARN) of the Users dataset you are adding the
-- user or users to.
putUsers_datasetArn :: Lens.Lens' PutUsers Prelude.Text
putUsers_datasetArn :: (Text -> f Text) -> PutUsers -> f PutUsers
putUsers_datasetArn = (PutUsers -> Text)
-> (PutUsers -> Text -> PutUsers)
-> Lens PutUsers PutUsers Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutUsers' {Text
datasetArn :: Text
$sel:datasetArn:PutUsers' :: PutUsers -> Text
datasetArn} -> Text
datasetArn) (\s :: PutUsers
s@PutUsers' {} Text
a -> PutUsers
s {$sel:datasetArn:PutUsers' :: Text
datasetArn = Text
a} :: PutUsers)

-- | A list of user data.
putUsers_users :: Lens.Lens' PutUsers (Prelude.NonEmpty User)
putUsers_users :: (NonEmpty User -> f (NonEmpty User)) -> PutUsers -> f PutUsers
putUsers_users = (PutUsers -> NonEmpty User)
-> (PutUsers -> NonEmpty User -> PutUsers)
-> Lens PutUsers PutUsers (NonEmpty User) (NonEmpty User)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutUsers' {NonEmpty User
users :: NonEmpty User
$sel:users:PutUsers' :: PutUsers -> NonEmpty User
users} -> NonEmpty User
users) (\s :: PutUsers
s@PutUsers' {} NonEmpty User
a -> PutUsers
s {$sel:users:PutUsers' :: NonEmpty User
users = NonEmpty User
a} :: PutUsers) ((NonEmpty User -> f (NonEmpty User)) -> PutUsers -> f PutUsers)
-> ((NonEmpty User -> f (NonEmpty User))
    -> NonEmpty User -> f (NonEmpty User))
-> (NonEmpty User -> f (NonEmpty User))
-> PutUsers
-> f PutUsers
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty User -> f (NonEmpty User))
-> NonEmpty User -> f (NonEmpty User)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest PutUsers where
  type AWSResponse PutUsers = PutUsersResponse
  request :: PutUsers -> Request PutUsers
request = Service -> PutUsers -> Request PutUsers
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutUsers
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutUsers)))
response = AWSResponse PutUsers
-> Logger
-> Service
-> Proxy PutUsers
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutUsers)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse PutUsers
PutUsersResponse
PutUsersResponse'

instance Prelude.Hashable PutUsers

instance Prelude.NFData PutUsers

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

instance Core.ToJSON PutUsers where
  toJSON :: PutUsers -> Value
toJSON PutUsers' {NonEmpty User
Text
users :: NonEmpty User
datasetArn :: Text
$sel:users:PutUsers' :: PutUsers -> NonEmpty User
$sel:datasetArn:PutUsers' :: PutUsers -> 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
"datasetArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
datasetArn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"users" Text -> NonEmpty User -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty User
users)
          ]
      )

instance Core.ToPath PutUsers where
  toPath :: PutUsers -> ByteString
toPath = ByteString -> PutUsers -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/users"

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

-- | /See:/ 'newPutUsersResponse' smart constructor.
data PutUsersResponse = PutUsersResponse'
  {
  }
  deriving (PutUsersResponse -> PutUsersResponse -> Bool
(PutUsersResponse -> PutUsersResponse -> Bool)
-> (PutUsersResponse -> PutUsersResponse -> Bool)
-> Eq PutUsersResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutUsersResponse -> PutUsersResponse -> Bool
$c/= :: PutUsersResponse -> PutUsersResponse -> Bool
== :: PutUsersResponse -> PutUsersResponse -> Bool
$c== :: PutUsersResponse -> PutUsersResponse -> Bool
Prelude.Eq, ReadPrec [PutUsersResponse]
ReadPrec PutUsersResponse
Int -> ReadS PutUsersResponse
ReadS [PutUsersResponse]
(Int -> ReadS PutUsersResponse)
-> ReadS [PutUsersResponse]
-> ReadPrec PutUsersResponse
-> ReadPrec [PutUsersResponse]
-> Read PutUsersResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutUsersResponse]
$creadListPrec :: ReadPrec [PutUsersResponse]
readPrec :: ReadPrec PutUsersResponse
$creadPrec :: ReadPrec PutUsersResponse
readList :: ReadS [PutUsersResponse]
$creadList :: ReadS [PutUsersResponse]
readsPrec :: Int -> ReadS PutUsersResponse
$creadsPrec :: Int -> ReadS PutUsersResponse
Prelude.Read, Int -> PutUsersResponse -> ShowS
[PutUsersResponse] -> ShowS
PutUsersResponse -> String
(Int -> PutUsersResponse -> ShowS)
-> (PutUsersResponse -> String)
-> ([PutUsersResponse] -> ShowS)
-> Show PutUsersResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutUsersResponse] -> ShowS
$cshowList :: [PutUsersResponse] -> ShowS
show :: PutUsersResponse -> String
$cshow :: PutUsersResponse -> String
showsPrec :: Int -> PutUsersResponse -> ShowS
$cshowsPrec :: Int -> PutUsersResponse -> ShowS
Prelude.Show, (forall x. PutUsersResponse -> Rep PutUsersResponse x)
-> (forall x. Rep PutUsersResponse x -> PutUsersResponse)
-> Generic PutUsersResponse
forall x. Rep PutUsersResponse x -> PutUsersResponse
forall x. PutUsersResponse -> Rep PutUsersResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutUsersResponse x -> PutUsersResponse
$cfrom :: forall x. PutUsersResponse -> Rep PutUsersResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutUsersResponse' 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.
newPutUsersResponse ::
  PutUsersResponse
newPutUsersResponse :: PutUsersResponse
newPutUsersResponse = PutUsersResponse
PutUsersResponse'

instance Prelude.NFData PutUsersResponse