{-# 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.DynamoDB.Types.PutRequest
-- 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)
module Amazonka.DynamoDB.Types.PutRequest where

import qualified Amazonka.Core as Core
import Amazonka.DynamoDB.Types.AttributeValue
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents a request to perform a @PutItem@ operation on an item.
--
-- /See:/ 'newPutRequest' smart constructor.
data PutRequest = PutRequest'
  { -- | A map of attribute name to attribute values, representing the primary
    -- key of an item to be processed by @PutItem@. All of the table\'s primary
    -- key attributes must be specified, and their data types must match those
    -- of the table\'s key schema. If any attributes are present in the item
    -- that are part of an index key schema for the table, their types must
    -- match the index key schema.
    PutRequest -> HashMap Text AttributeValue
item :: Prelude.HashMap Prelude.Text AttributeValue
  }
  deriving (PutRequest -> PutRequest -> Bool
(PutRequest -> PutRequest -> Bool)
-> (PutRequest -> PutRequest -> Bool) -> Eq PutRequest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutRequest -> PutRequest -> Bool
$c/= :: PutRequest -> PutRequest -> Bool
== :: PutRequest -> PutRequest -> Bool
$c== :: PutRequest -> PutRequest -> Bool
Prelude.Eq, ReadPrec [PutRequest]
ReadPrec PutRequest
Int -> ReadS PutRequest
ReadS [PutRequest]
(Int -> ReadS PutRequest)
-> ReadS [PutRequest]
-> ReadPrec PutRequest
-> ReadPrec [PutRequest]
-> Read PutRequest
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutRequest]
$creadListPrec :: ReadPrec [PutRequest]
readPrec :: ReadPrec PutRequest
$creadPrec :: ReadPrec PutRequest
readList :: ReadS [PutRequest]
$creadList :: ReadS [PutRequest]
readsPrec :: Int -> ReadS PutRequest
$creadsPrec :: Int -> ReadS PutRequest
Prelude.Read, Int -> PutRequest -> ShowS
[PutRequest] -> ShowS
PutRequest -> String
(Int -> PutRequest -> ShowS)
-> (PutRequest -> String)
-> ([PutRequest] -> ShowS)
-> Show PutRequest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutRequest] -> ShowS
$cshowList :: [PutRequest] -> ShowS
show :: PutRequest -> String
$cshow :: PutRequest -> String
showsPrec :: Int -> PutRequest -> ShowS
$cshowsPrec :: Int -> PutRequest -> ShowS
Prelude.Show, (forall x. PutRequest -> Rep PutRequest x)
-> (forall x. Rep PutRequest x -> PutRequest) -> Generic PutRequest
forall x. Rep PutRequest x -> PutRequest
forall x. PutRequest -> Rep PutRequest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutRequest x -> PutRequest
$cfrom :: forall x. PutRequest -> Rep PutRequest x
Prelude.Generic)

-- |
-- Create a value of 'PutRequest' 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:
--
-- 'item', 'putRequest_item' - A map of attribute name to attribute values, representing the primary
-- key of an item to be processed by @PutItem@. All of the table\'s primary
-- key attributes must be specified, and their data types must match those
-- of the table\'s key schema. If any attributes are present in the item
-- that are part of an index key schema for the table, their types must
-- match the index key schema.
newPutRequest ::
  PutRequest
newPutRequest :: PutRequest
newPutRequest = PutRequest' :: HashMap Text AttributeValue -> PutRequest
PutRequest' {$sel:item:PutRequest' :: HashMap Text AttributeValue
item = HashMap Text AttributeValue
forall a. Monoid a => a
Prelude.mempty}

-- | A map of attribute name to attribute values, representing the primary
-- key of an item to be processed by @PutItem@. All of the table\'s primary
-- key attributes must be specified, and their data types must match those
-- of the table\'s key schema. If any attributes are present in the item
-- that are part of an index key schema for the table, their types must
-- match the index key schema.
putRequest_item :: Lens.Lens' PutRequest (Prelude.HashMap Prelude.Text AttributeValue)
putRequest_item :: (HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
-> PutRequest -> f PutRequest
putRequest_item = (PutRequest -> HashMap Text AttributeValue)
-> (PutRequest -> HashMap Text AttributeValue -> PutRequest)
-> Lens
     PutRequest
     PutRequest
     (HashMap Text AttributeValue)
     (HashMap Text AttributeValue)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRequest' {HashMap Text AttributeValue
item :: HashMap Text AttributeValue
$sel:item:PutRequest' :: PutRequest -> HashMap Text AttributeValue
item} -> HashMap Text AttributeValue
item) (\s :: PutRequest
s@PutRequest' {} HashMap Text AttributeValue
a -> PutRequest
s {$sel:item:PutRequest' :: HashMap Text AttributeValue
item = HashMap Text AttributeValue
a} :: PutRequest) ((HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
 -> PutRequest -> f PutRequest)
-> ((HashMap Text AttributeValue
     -> f (HashMap Text AttributeValue))
    -> HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
-> (HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
-> PutRequest
-> f PutRequest
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text AttributeValue -> f (HashMap Text AttributeValue))
-> HashMap Text AttributeValue -> f (HashMap Text AttributeValue)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON PutRequest where
  parseJSON :: Value -> Parser PutRequest
parseJSON =
    String
-> (Object -> Parser PutRequest) -> Value -> Parser PutRequest
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PutRequest"
      ( \Object
x ->
          HashMap Text AttributeValue -> PutRequest
PutRequest'
            (HashMap Text AttributeValue -> PutRequest)
-> Parser (HashMap Text AttributeValue) -> Parser PutRequest
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (HashMap Text AttributeValue))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Item" Parser (Maybe (HashMap Text AttributeValue))
-> HashMap Text AttributeValue
-> Parser (HashMap Text AttributeValue)
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= HashMap Text AttributeValue
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable PutRequest

instance Prelude.NFData PutRequest

instance Core.ToJSON PutRequest where
  toJSON :: PutRequest -> Value
toJSON PutRequest' {HashMap Text AttributeValue
item :: HashMap Text AttributeValue
$sel:item:PutRequest' :: PutRequest -> HashMap Text AttributeValue
..} =
    [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
"Item" Text -> HashMap Text AttributeValue -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text AttributeValue
item)]
      )