{-# 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.PutItems
-- 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 items to an Items dataset. For more information see
-- <https://docs.aws.amazon.com/personalize/latest/dg/importing-items.html Importing Items Incrementally>.
module Amazonka.PersonalizeEvents.PutItems
  ( -- * Creating a Request
    PutItems (..),
    newPutItems,

    -- * Request Lenses
    putItems_datasetArn,
    putItems_items,

    -- * Destructuring the Response
    PutItemsResponse (..),
    newPutItemsResponse,
  )
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:/ 'newPutItems' smart constructor.
data PutItems = PutItems'
  { -- | The Amazon Resource Name (ARN) of the Items dataset you are adding the
    -- item or items to.
    PutItems -> Text
datasetArn :: Prelude.Text,
    -- | A list of item data.
    PutItems -> NonEmpty Item
items :: Prelude.NonEmpty Item
  }
  deriving (PutItems -> PutItems -> Bool
(PutItems -> PutItems -> Bool)
-> (PutItems -> PutItems -> Bool) -> Eq PutItems
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutItems -> PutItems -> Bool
$c/= :: PutItems -> PutItems -> Bool
== :: PutItems -> PutItems -> Bool
$c== :: PutItems -> PutItems -> Bool
Prelude.Eq, ReadPrec [PutItems]
ReadPrec PutItems
Int -> ReadS PutItems
ReadS [PutItems]
(Int -> ReadS PutItems)
-> ReadS [PutItems]
-> ReadPrec PutItems
-> ReadPrec [PutItems]
-> Read PutItems
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutItems]
$creadListPrec :: ReadPrec [PutItems]
readPrec :: ReadPrec PutItems
$creadPrec :: ReadPrec PutItems
readList :: ReadS [PutItems]
$creadList :: ReadS [PutItems]
readsPrec :: Int -> ReadS PutItems
$creadsPrec :: Int -> ReadS PutItems
Prelude.Read, Int -> PutItems -> ShowS
[PutItems] -> ShowS
PutItems -> String
(Int -> PutItems -> ShowS)
-> (PutItems -> String) -> ([PutItems] -> ShowS) -> Show PutItems
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutItems] -> ShowS
$cshowList :: [PutItems] -> ShowS
show :: PutItems -> String
$cshow :: PutItems -> String
showsPrec :: Int -> PutItems -> ShowS
$cshowsPrec :: Int -> PutItems -> ShowS
Prelude.Show, (forall x. PutItems -> Rep PutItems x)
-> (forall x. Rep PutItems x -> PutItems) -> Generic PutItems
forall x. Rep PutItems x -> PutItems
forall x. PutItems -> Rep PutItems x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutItems x -> PutItems
$cfrom :: forall x. PutItems -> Rep PutItems x
Prelude.Generic)

-- |
-- Create a value of 'PutItems' 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', 'putItems_datasetArn' - The Amazon Resource Name (ARN) of the Items dataset you are adding the
-- item or items to.
--
-- 'items', 'putItems_items' - A list of item data.
newPutItems ::
  -- | 'datasetArn'
  Prelude.Text ->
  -- | 'items'
  Prelude.NonEmpty Item ->
  PutItems
newPutItems :: Text -> NonEmpty Item -> PutItems
newPutItems Text
pDatasetArn_ NonEmpty Item
pItems_ =
  PutItems' :: Text -> NonEmpty Item -> PutItems
PutItems'
    { $sel:datasetArn:PutItems' :: Text
datasetArn = Text
pDatasetArn_,
      $sel:items:PutItems' :: NonEmpty Item
items = Tagged (NonEmpty Item) (Identity (NonEmpty Item))
-> Tagged (NonEmpty Item) (Identity (NonEmpty Item))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Item) (Identity (NonEmpty Item))
 -> Tagged (NonEmpty Item) (Identity (NonEmpty Item)))
-> NonEmpty Item -> NonEmpty Item
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Item
pItems_
    }

-- | The Amazon Resource Name (ARN) of the Items dataset you are adding the
-- item or items to.
putItems_datasetArn :: Lens.Lens' PutItems Prelude.Text
putItems_datasetArn :: (Text -> f Text) -> PutItems -> f PutItems
putItems_datasetArn = (PutItems -> Text)
-> (PutItems -> Text -> PutItems)
-> Lens PutItems PutItems Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutItems' {Text
datasetArn :: Text
$sel:datasetArn:PutItems' :: PutItems -> Text
datasetArn} -> Text
datasetArn) (\s :: PutItems
s@PutItems' {} Text
a -> PutItems
s {$sel:datasetArn:PutItems' :: Text
datasetArn = Text
a} :: PutItems)

-- | A list of item data.
putItems_items :: Lens.Lens' PutItems (Prelude.NonEmpty Item)
putItems_items :: (NonEmpty Item -> f (NonEmpty Item)) -> PutItems -> f PutItems
putItems_items = (PutItems -> NonEmpty Item)
-> (PutItems -> NonEmpty Item -> PutItems)
-> Lens PutItems PutItems (NonEmpty Item) (NonEmpty Item)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutItems' {NonEmpty Item
items :: NonEmpty Item
$sel:items:PutItems' :: PutItems -> NonEmpty Item
items} -> NonEmpty Item
items) (\s :: PutItems
s@PutItems' {} NonEmpty Item
a -> PutItems
s {$sel:items:PutItems' :: NonEmpty Item
items = NonEmpty Item
a} :: PutItems) ((NonEmpty Item -> f (NonEmpty Item)) -> PutItems -> f PutItems)
-> ((NonEmpty Item -> f (NonEmpty Item))
    -> NonEmpty Item -> f (NonEmpty Item))
-> (NonEmpty Item -> f (NonEmpty Item))
-> PutItems
-> f PutItems
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Item -> f (NonEmpty Item))
-> NonEmpty Item -> f (NonEmpty Item)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable PutItems

instance Prelude.NFData PutItems

instance Core.ToHeaders PutItems where
  toHeaders :: PutItems -> [Header]
toHeaders =
    [Header] -> PutItems -> [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 PutItems where
  toJSON :: PutItems -> Value
toJSON PutItems' {NonEmpty Item
Text
items :: NonEmpty Item
datasetArn :: Text
$sel:items:PutItems' :: PutItems -> NonEmpty Item
$sel:datasetArn:PutItems' :: PutItems -> 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
"items" Text -> NonEmpty Item -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Item
items)
          ]
      )

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

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

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

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

instance Prelude.NFData PutItemsResponse