{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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, Int -> PutItems -> ShowS
[PutItems] -> ShowS
PutItems -> String
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. 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'
    { $sel:datasetArn:PutItems' :: Text
datasetArn = Text
pDatasetArn_,
      $sel:items:PutItems' :: NonEmpty Item
items = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced 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 :: Lens' PutItems Text
putItems_datasetArn = 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 :: Lens' PutItems (NonEmpty Item)
putItems_items = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 :: (Service -> Service) -> PutItems -> Request PutItems
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy PutItems
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutItems)))
response = forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull PutItemsResponse
PutItemsResponse'

instance Prelude.Hashable PutItems where
  hashWithSalt :: Int -> PutItems -> Int
hashWithSalt Int
_salt PutItems' {NonEmpty Item
Text
items :: NonEmpty Item
datasetArn :: Text
$sel:items:PutItems' :: PutItems -> NonEmpty Item
$sel:datasetArn:PutItems' :: PutItems -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
datasetArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Item
items

instance Prelude.NFData PutItems where
  rnf :: PutItems -> ()
rnf PutItems' {NonEmpty Item
Text
items :: NonEmpty Item
datasetArn :: Text
$sel:items:PutItems' :: PutItems -> NonEmpty Item
$sel:datasetArn:PutItems' :: PutItems -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
datasetArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Item
items

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

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"datasetArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
datasetArn),
            forall a. a -> Maybe a
Prelude.Just (Key
"items" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Item
items)
          ]
      )

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

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

-- | /See:/ 'newPutItemsResponse' smart constructor.
data PutItemsResponse = PutItemsResponse'
  {
  }
  deriving (PutItemsResponse -> PutItemsResponse -> Bool
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]
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
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. 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 where
  rnf :: PutItemsResponse -> ()
rnf PutItemsResponse
_ = ()