{-# LANGUAGE DeriveDataTypeable        #-}
{-# LANGUAGE FlexibleContexts          #-}
{-# LANGUAGE FlexibleInstances         #-}
{-# LANGUAGE MultiParamTypeClasses     #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE OverloadedStrings         #-}
{-# LANGUAGE RecordWildCards           #-}
{-# LANGUAGE ScopedTypeVariables       #-}
{-# LANGUAGE TypeFamilies              #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Aws.DynamoDb.Commands.BatchWriteItem
-- Copyright   :  Soostone Inc
-- License     :  BSD3
--
-- Maintainer  :  Justin Dawson <jtdawso@gmail.com>
-- Stability   :  experimental
--
-- @http:\/\/docs.aws.amazon.com\/amazondynamodb\/latest\/APIReference\/API_BatchWriteItem.html@
----------------------------------------------------------------------------

module Aws.DynamoDb.Commands.BatchWriteItem where

-------------------------------------------------------------------------------
import           Control.Applicative
import           Data.Aeson
import           Data.Default
import           Data.Foldable (asum)
import qualified Data.HashMap.Strict as HM
import qualified Data.Text           as T
import           Prelude
-------------------------------------------------------------------------------
import           Aws.Core
import           Aws.DynamoDb.Core
import           Aws.DynamoDb.Commands.PutItem
import           Aws.DynamoDb.Commands.DeleteItem
-------------------------------------------------------------------------------


data Request = PutRequest { Request -> Item
prItem :: Item }
             | DeleteRequest {Request -> PrimaryKey
drKey :: PrimaryKey}
     deriving (Request -> Request -> Bool
(Request -> Request -> Bool)
-> (Request -> Request -> Bool) -> Eq Request
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Request -> Request -> Bool
$c/= :: Request -> Request -> Bool
== :: Request -> Request -> Bool
$c== :: Request -> Request -> Bool
Eq,Int -> Request -> ShowS
[Request] -> ShowS
Request -> String
(Int -> Request -> ShowS)
-> (Request -> String) -> ([Request] -> ShowS) -> Show Request
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Request] -> ShowS
$cshowList :: [Request] -> ShowS
show :: Request -> String
$cshow :: Request -> String
showsPrec :: Int -> Request -> ShowS
$cshowsPrec :: Int -> Request -> ShowS
Show,ReadPrec [Request]
ReadPrec Request
Int -> ReadS Request
ReadS [Request]
(Int -> ReadS Request)
-> ReadS [Request]
-> ReadPrec Request
-> ReadPrec [Request]
-> Read Request
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Request]
$creadListPrec :: ReadPrec [Request]
readPrec :: ReadPrec Request
$creadPrec :: ReadPrec Request
readList :: ReadS [Request]
$creadList :: ReadS [Request]
readsPrec :: Int -> ReadS Request
$creadsPrec :: Int -> ReadS Request
Read,Eq Request
Eq Request
-> (Request -> Request -> Ordering)
-> (Request -> Request -> Bool)
-> (Request -> Request -> Bool)
-> (Request -> Request -> Bool)
-> (Request -> Request -> Bool)
-> (Request -> Request -> Request)
-> (Request -> Request -> Request)
-> Ord Request
Request -> Request -> Bool
Request -> Request -> Ordering
Request -> Request -> Request
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Request -> Request -> Request
$cmin :: Request -> Request -> Request
max :: Request -> Request -> Request
$cmax :: Request -> Request -> Request
>= :: Request -> Request -> Bool
$c>= :: Request -> Request -> Bool
> :: Request -> Request -> Bool
$c> :: Request -> Request -> Bool
<= :: Request -> Request -> Bool
$c<= :: Request -> Request -> Bool
< :: Request -> Request -> Bool
$c< :: Request -> Request -> Bool
compare :: Request -> Request -> Ordering
$ccompare :: Request -> Request -> Ordering
$cp1Ord :: Eq Request
Ord)

data BatchWriteItem = BatchWriteItem {
      BatchWriteItem -> [(Text, [Request])]
bwRequests :: [(T.Text,[Request])]
    -- ^ Put or Delete Requests for a specified table
    , BatchWriteItem -> ReturnConsumption
bwRetCons :: ReturnConsumption
    , BatchWriteItem -> ReturnItemCollectionMetrics
bwRetMet  :: ReturnItemCollectionMetrics
    } deriving (BatchWriteItem -> BatchWriteItem -> Bool
(BatchWriteItem -> BatchWriteItem -> Bool)
-> (BatchWriteItem -> BatchWriteItem -> Bool) -> Eq BatchWriteItem
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchWriteItem -> BatchWriteItem -> Bool
$c/= :: BatchWriteItem -> BatchWriteItem -> Bool
== :: BatchWriteItem -> BatchWriteItem -> Bool
$c== :: BatchWriteItem -> BatchWriteItem -> Bool
Eq,Int -> BatchWriteItem -> ShowS
[BatchWriteItem] -> ShowS
BatchWriteItem -> String
(Int -> BatchWriteItem -> ShowS)
-> (BatchWriteItem -> String)
-> ([BatchWriteItem] -> ShowS)
-> Show BatchWriteItem
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchWriteItem] -> ShowS
$cshowList :: [BatchWriteItem] -> ShowS
show :: BatchWriteItem -> String
$cshow :: BatchWriteItem -> String
showsPrec :: Int -> BatchWriteItem -> ShowS
$cshowsPrec :: Int -> BatchWriteItem -> ShowS
Show,ReadPrec [BatchWriteItem]
ReadPrec BatchWriteItem
Int -> ReadS BatchWriteItem
ReadS [BatchWriteItem]
(Int -> ReadS BatchWriteItem)
-> ReadS [BatchWriteItem]
-> ReadPrec BatchWriteItem
-> ReadPrec [BatchWriteItem]
-> Read BatchWriteItem
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchWriteItem]
$creadListPrec :: ReadPrec [BatchWriteItem]
readPrec :: ReadPrec BatchWriteItem
$creadPrec :: ReadPrec BatchWriteItem
readList :: ReadS [BatchWriteItem]
$creadList :: ReadS [BatchWriteItem]
readsPrec :: Int -> ReadS BatchWriteItem
$creadsPrec :: Int -> ReadS BatchWriteItem
Read,Eq BatchWriteItem
Eq BatchWriteItem
-> (BatchWriteItem -> BatchWriteItem -> Ordering)
-> (BatchWriteItem -> BatchWriteItem -> Bool)
-> (BatchWriteItem -> BatchWriteItem -> Bool)
-> (BatchWriteItem -> BatchWriteItem -> Bool)
-> (BatchWriteItem -> BatchWriteItem -> Bool)
-> (BatchWriteItem -> BatchWriteItem -> BatchWriteItem)
-> (BatchWriteItem -> BatchWriteItem -> BatchWriteItem)
-> Ord BatchWriteItem
BatchWriteItem -> BatchWriteItem -> Bool
BatchWriteItem -> BatchWriteItem -> Ordering
BatchWriteItem -> BatchWriteItem -> BatchWriteItem
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: BatchWriteItem -> BatchWriteItem -> BatchWriteItem
$cmin :: BatchWriteItem -> BatchWriteItem -> BatchWriteItem
max :: BatchWriteItem -> BatchWriteItem -> BatchWriteItem
$cmax :: BatchWriteItem -> BatchWriteItem -> BatchWriteItem
>= :: BatchWriteItem -> BatchWriteItem -> Bool
$c>= :: BatchWriteItem -> BatchWriteItem -> Bool
> :: BatchWriteItem -> BatchWriteItem -> Bool
$c> :: BatchWriteItem -> BatchWriteItem -> Bool
<= :: BatchWriteItem -> BatchWriteItem -> Bool
$c<= :: BatchWriteItem -> BatchWriteItem -> Bool
< :: BatchWriteItem -> BatchWriteItem -> Bool
$c< :: BatchWriteItem -> BatchWriteItem -> Bool
compare :: BatchWriteItem -> BatchWriteItem -> Ordering
$ccompare :: BatchWriteItem -> BatchWriteItem -> Ordering
$cp1Ord :: Eq BatchWriteItem
Ord)


-------------------------------------------------------------------------------

toBatchWrite :: [PutItem]
           -> [DeleteItem]
           -> BatchWriteItem
toBatchWrite :: [PutItem] -> [DeleteItem] -> BatchWriteItem
toBatchWrite [PutItem]
ps [DeleteItem]
ds =[(Text, [Request])]
-> ReturnConsumption
-> ReturnItemCollectionMetrics
-> BatchWriteItem
BatchWriteItem [(Text, [Request])]
maps ReturnConsumption
forall a. Default a => a
def ReturnItemCollectionMetrics
forall a. Default a => a
def  
      where
        maps :: [(T.Text,[Request])]
        maps :: [(Text, [Request])]
maps = let pMap :: HashMap Text [Request]
pMap = (HashMap Text [Request] -> PutItem -> HashMap Text [Request])
-> HashMap Text [Request] -> [PutItem] -> HashMap Text [Request]
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl (\HashMap Text [Request]
acc PutItem
p -> let key :: Text
key = PutItem -> Text
piTable PutItem
p
                                             in Text
-> [Request] -> HashMap Text [Request] -> HashMap Text [Request]
forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
HM.insert Text
key (Item -> Request
PutRequest (PutItem -> Item
piItem PutItem
p) Request -> [Request] -> [Request]
forall a. a -> [a] -> [a]
: ([Request] -> Text -> HashMap Text [Request] -> [Request]
forall k v. (Eq k, Hashable k) => v -> k -> HashMap k v -> v
HM.lookupDefault [] Text
key HashMap Text [Request]
acc)) HashMap Text [Request]
acc) HashMap Text [Request]
forall k v. HashMap k v
HM.empty [PutItem]
ps 
                   totalMap :: HashMap Text [Request]
totalMap = (HashMap Text [Request] -> DeleteItem -> HashMap Text [Request])
-> HashMap Text [Request] -> [DeleteItem] -> HashMap Text [Request]
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl (\HashMap Text [Request]
acc DeleteItem
d -> let key :: Text
key = DeleteItem -> Text
diTable DeleteItem
d
                                                 in  Text
-> [Request] -> HashMap Text [Request] -> HashMap Text [Request]
forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
HM.insert Text
key (PrimaryKey -> Request
DeleteRequest (DeleteItem -> PrimaryKey
diKey DeleteItem
d) Request -> [Request] -> [Request]
forall a. a -> [a] -> [a]
: ([Request] -> Text -> HashMap Text [Request] -> [Request]
forall k v. (Eq k, Hashable k) => v -> k -> HashMap k v -> v
HM.lookupDefault [] Text
key HashMap Text [Request]
acc)) HashMap Text [Request]
acc) HashMap Text [Request]
pMap [DeleteItem]
ds
                 in  HashMap Text [Request] -> [(Text, [Request])]
forall k v. HashMap k v -> [(k, v)]
HM.toList HashMap Text [Request]
totalMap
-- | Construct a BatchWriteItem
batchWriteItem :: [(T.Text,[Request])]
               -> BatchWriteItem
batchWriteItem :: [(Text, [Request])] -> BatchWriteItem
batchWriteItem [(Text, [Request])]
reqs = [(Text, [Request])]
-> ReturnConsumption
-> ReturnItemCollectionMetrics
-> BatchWriteItem
BatchWriteItem [(Text, [Request])]
reqs ReturnConsumption
forall a. Default a => a
def ReturnItemCollectionMetrics
forall a. Default a => a
def


instance ToJSON Request where
   toJSON :: Request -> Value
toJSON PutRequest{Item
prItem :: Item
prItem :: Request -> Item
..} =
       [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
         [ Key
"PutRequest" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= ([Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$ [Key
"Item" Key -> Item -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Item
prItem])
         ]
   toJSON DeleteRequest{PrimaryKey
drKey :: PrimaryKey
drKey :: Request -> PrimaryKey
..} =
       [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
         [ Key
"DeleteRequest" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.=  ([Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$ [Key
"Key" Key -> PrimaryKey -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= PrimaryKey
drKey])
         ]

instance ToJSON BatchWriteItem where
    toJSON :: BatchWriteItem -> Value
toJSON BatchWriteItem{[(Text, [Request])]
ReturnItemCollectionMetrics
ReturnConsumption
bwRetMet :: ReturnItemCollectionMetrics
bwRetCons :: ReturnConsumption
bwRequests :: [(Text, [Request])]
bwRetMet :: BatchWriteItem -> ReturnItemCollectionMetrics
bwRetCons :: BatchWriteItem -> ReturnConsumption
bwRequests :: BatchWriteItem -> [(Text, [Request])]
..} =
        [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
          [ Key
"RequestItems" Key -> HashMap Text [Request] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [(Text, [Request])] -> HashMap Text [Request]
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HM.fromList [(Text, [Request])]
bwRequests
          , Key
"ReturnConsumedCapacity" Key -> ReturnConsumption -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= ReturnConsumption
bwRetCons
          , Key
"ReturnItemCollectionMetrics" Key -> ReturnItemCollectionMetrics -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= ReturnItemCollectionMetrics
bwRetMet
          ]

instance FromJSON Request where
    parseJSON :: Value -> Parser Request
parseJSON = String -> (Object -> Parser Request) -> Value -> Parser Request
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"PutRequest or DeleteRequest" ((Object -> Parser Request) -> Value -> Parser Request)
-> (Object -> Parser Request) -> Value -> Parser Request
forall a b. (a -> b) -> a -> b
$ \Object
o ->
     
     [Parser Request] -> Parser Request
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum [
           do
             Object
pr <- Object
o Object -> Key -> Parser Object
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"PutRequest"
             Item
i  <- Object
pr Object -> Key -> Parser Item
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"Item"
             Request -> Parser Request
forall (m :: * -> *) a. Monad m => a -> m a
return (Request -> Parser Request) -> Request -> Parser Request
forall a b. (a -> b) -> a -> b
$ Item -> Request
PutRequest Item
i ,
           do
             Object
dr <- Object
o Object -> Key -> Parser Object
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"DeleteRequest"
             PrimaryKey
pk <- Object
dr Object -> Key -> Parser PrimaryKey
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"Key"
             Request -> Parser Request
forall (m :: * -> *) a. Monad m => a -> m a
return (Request -> Parser Request) -> Request -> Parser Request
forall a b. (a -> b) -> a -> b
$ PrimaryKey -> Request
DeleteRequest PrimaryKey
pk
          ]
    
data BatchWriteItemResponse = BatchWriteItemResponse {
      BatchWriteItemResponse -> [(Text, [Request])]
bwUnprocessed    :: [(T.Text,[Request])]
    -- ^ Unprocessed Requests on failure
    , BatchWriteItemResponse -> Maybe ConsumedCapacity
bwConsumed :: Maybe ConsumedCapacity
    -- ^ Amount of capacity consumed
    , BatchWriteItemResponse -> Maybe ItemCollectionMetrics
bwColMet   :: Maybe ItemCollectionMetrics
    -- ^ Collection metrics for tables affected by BatchWriteItem.
    } deriving (BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
(BatchWriteItemResponse -> BatchWriteItemResponse -> Bool)
-> (BatchWriteItemResponse -> BatchWriteItemResponse -> Bool)
-> Eq BatchWriteItemResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
$c/= :: BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
== :: BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
$c== :: BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
Eq,Int -> BatchWriteItemResponse -> ShowS
[BatchWriteItemResponse] -> ShowS
BatchWriteItemResponse -> String
(Int -> BatchWriteItemResponse -> ShowS)
-> (BatchWriteItemResponse -> String)
-> ([BatchWriteItemResponse] -> ShowS)
-> Show BatchWriteItemResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchWriteItemResponse] -> ShowS
$cshowList :: [BatchWriteItemResponse] -> ShowS
show :: BatchWriteItemResponse -> String
$cshow :: BatchWriteItemResponse -> String
showsPrec :: Int -> BatchWriteItemResponse -> ShowS
$cshowsPrec :: Int -> BatchWriteItemResponse -> ShowS
Show,ReadPrec [BatchWriteItemResponse]
ReadPrec BatchWriteItemResponse
Int -> ReadS BatchWriteItemResponse
ReadS [BatchWriteItemResponse]
(Int -> ReadS BatchWriteItemResponse)
-> ReadS [BatchWriteItemResponse]
-> ReadPrec BatchWriteItemResponse
-> ReadPrec [BatchWriteItemResponse]
-> Read BatchWriteItemResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchWriteItemResponse]
$creadListPrec :: ReadPrec [BatchWriteItemResponse]
readPrec :: ReadPrec BatchWriteItemResponse
$creadPrec :: ReadPrec BatchWriteItemResponse
readList :: ReadS [BatchWriteItemResponse]
$creadList :: ReadS [BatchWriteItemResponse]
readsPrec :: Int -> ReadS BatchWriteItemResponse
$creadsPrec :: Int -> ReadS BatchWriteItemResponse
Read,Eq BatchWriteItemResponse
Eq BatchWriteItemResponse
-> (BatchWriteItemResponse -> BatchWriteItemResponse -> Ordering)
-> (BatchWriteItemResponse -> BatchWriteItemResponse -> Bool)
-> (BatchWriteItemResponse -> BatchWriteItemResponse -> Bool)
-> (BatchWriteItemResponse -> BatchWriteItemResponse -> Bool)
-> (BatchWriteItemResponse -> BatchWriteItemResponse -> Bool)
-> (BatchWriteItemResponse
    -> BatchWriteItemResponse -> BatchWriteItemResponse)
-> (BatchWriteItemResponse
    -> BatchWriteItemResponse -> BatchWriteItemResponse)
-> Ord BatchWriteItemResponse
BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
BatchWriteItemResponse -> BatchWriteItemResponse -> Ordering
BatchWriteItemResponse
-> BatchWriteItemResponse -> BatchWriteItemResponse
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: BatchWriteItemResponse
-> BatchWriteItemResponse -> BatchWriteItemResponse
$cmin :: BatchWriteItemResponse
-> BatchWriteItemResponse -> BatchWriteItemResponse
max :: BatchWriteItemResponse
-> BatchWriteItemResponse -> BatchWriteItemResponse
$cmax :: BatchWriteItemResponse
-> BatchWriteItemResponse -> BatchWriteItemResponse
>= :: BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
$c>= :: BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
> :: BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
$c> :: BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
<= :: BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
$c<= :: BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
< :: BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
$c< :: BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
compare :: BatchWriteItemResponse -> BatchWriteItemResponse -> Ordering
$ccompare :: BatchWriteItemResponse -> BatchWriteItemResponse -> Ordering
$cp1Ord :: Eq BatchWriteItemResponse
Ord)



instance Transaction BatchWriteItem BatchWriteItemResponse


instance SignQuery BatchWriteItem where
    type ServiceConfiguration BatchWriteItem = DdbConfiguration
    signQuery :: BatchWriteItem
-> ServiceConfiguration BatchWriteItem queryType
-> SignatureData
-> SignedQuery
signQuery BatchWriteItem
gi = ByteString
-> BatchWriteItem
-> DdbConfiguration queryType
-> SignatureData
-> SignedQuery
forall a qt.
ToJSON a =>
ByteString
-> a -> DdbConfiguration qt -> SignatureData -> SignedQuery
ddbSignQuery ByteString
"BatchWriteItem" BatchWriteItem
gi


instance FromJSON BatchWriteItemResponse where
    parseJSON :: Value -> Parser BatchWriteItemResponse
parseJSON (Object Object
v) = [(Text, [Request])]
-> Maybe ConsumedCapacity
-> Maybe ItemCollectionMetrics
-> BatchWriteItemResponse
BatchWriteItemResponse
        ([(Text, [Request])]
 -> Maybe ConsumedCapacity
 -> Maybe ItemCollectionMetrics
 -> BatchWriteItemResponse)
-> (HashMap Text [Request] -> [(Text, [Request])])
-> HashMap Text [Request]
-> Maybe ConsumedCapacity
-> Maybe ItemCollectionMetrics
-> BatchWriteItemResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HashMap Text [Request] -> [(Text, [Request])]
forall k v. HashMap k v -> [(k, v)]
HM.toList (HashMap Text [Request]
 -> Maybe ConsumedCapacity
 -> Maybe ItemCollectionMetrics
 -> BatchWriteItemResponse)
-> Parser (HashMap Text [Request])
-> Parser
     (Maybe ConsumedCapacity
      -> Maybe ItemCollectionMetrics -> BatchWriteItemResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Object
v Object -> Key -> Parser (HashMap Text [Request])
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"UnprocessedItems")
        Parser
  (Maybe ConsumedCapacity
   -> Maybe ItemCollectionMetrics -> BatchWriteItemResponse)
-> Parser (Maybe ConsumedCapacity)
-> Parser (Maybe ItemCollectionMetrics -> BatchWriteItemResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe ConsumedCapacity)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"ConsumedCapacity"
        Parser (Maybe ItemCollectionMetrics -> BatchWriteItemResponse)
-> Parser (Maybe ItemCollectionMetrics)
-> Parser BatchWriteItemResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe ItemCollectionMetrics)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"ItemCollectionMetrics"
    parseJSON Value
_ = String -> Parser BatchWriteItemResponse
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"BatchWriteItemResponse must be an object."


instance ResponseConsumer r BatchWriteItemResponse where
    type ResponseMetadata BatchWriteItemResponse = DdbResponse
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata BatchWriteItemResponse)
-> HTTPResponseConsumer BatchWriteItemResponse
responseConsumer Request
_ r
_ IORef (ResponseMetadata BatchWriteItemResponse)
ref Response (ConduitM () ByteString (ResourceT IO) ())
resp = IORef DdbResponse -> HTTPResponseConsumer BatchWriteItemResponse
forall a. FromJSON a => IORef DdbResponse -> HTTPResponseConsumer a
ddbResponseConsumer IORef (ResponseMetadata BatchWriteItemResponse)
IORef DdbResponse
ref Response (ConduitM () ByteString (ResourceT IO) ())
resp


instance AsMemoryResponse BatchWriteItemResponse where
    type MemoryResponse BatchWriteItemResponse = BatchWriteItemResponse
    loadToMemory :: BatchWriteItemResponse
-> ResourceT IO (MemoryResponse BatchWriteItemResponse)
loadToMemory = BatchWriteItemResponse
-> ResourceT IO (MemoryResponse BatchWriteItemResponse)
forall (m :: * -> *) a. Monad m => a -> m a
return