{-# LANGUAGE DeriveDataTypeable        #-}
{-# LANGUAGE FlexibleContexts          #-}
{-# LANGUAGE FlexibleInstances         #-}
{-# LANGUAGE MultiParamTypeClasses     #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE OverloadedStrings         #-}
{-# LANGUAGE RecordWildCards           #-}
{-# LANGUAGE ScopedTypeVariables       #-}
{-# LANGUAGE TypeFamilies              #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Aws.DynamoDb.Commands.DeleteItem
-- Copyright   :  Soostone Inc
-- License     :  BSD3
--
-- Maintainer  :  Ozgun Ataman <ozgun.ataman@soostone.com>
-- Stability   :  experimental
--
-- @http:\/\/docs.aws.amazon.com\/amazondynamodb\/latest\/APIReference\/API_DeleteItem.html@
----------------------------------------------------------------------------

module Aws.DynamoDb.Commands.DeleteItem where

-------------------------------------------------------------------------------
import           Control.Applicative
import           Data.Aeson
import           Data.Default
import qualified Data.Text           as T
import           Prelude
-------------------------------------------------------------------------------
import           Aws.Core
import           Aws.DynamoDb.Core
-------------------------------------------------------------------------------


data DeleteItem = DeleteItem {
      DeleteItem -> Text
diTable   :: T.Text
    -- ^ Target table
    , DeleteItem -> PrimaryKey
diKey     :: PrimaryKey
    -- ^ The item to delete.
    , DeleteItem -> Conditions
diExpect  :: Conditions
    -- ^ (Possible) set of expections for a conditional Put
    , DeleteItem -> UpdateReturn
diReturn  :: UpdateReturn
    -- ^ What to return from this query.
    , DeleteItem -> ReturnConsumption
diRetCons :: ReturnConsumption
    , DeleteItem -> ReturnItemCollectionMetrics
diRetMet  :: ReturnItemCollectionMetrics
    } deriving (DeleteItem -> DeleteItem -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteItem -> DeleteItem -> Bool
$c/= :: DeleteItem -> DeleteItem -> Bool
== :: DeleteItem -> DeleteItem -> Bool
$c== :: DeleteItem -> DeleteItem -> Bool
Eq,Int -> DeleteItem -> ShowS
[DeleteItem] -> ShowS
DeleteItem -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteItem] -> ShowS
$cshowList :: [DeleteItem] -> ShowS
show :: DeleteItem -> String
$cshow :: DeleteItem -> String
showsPrec :: Int -> DeleteItem -> ShowS
$cshowsPrec :: Int -> DeleteItem -> ShowS
Show,ReadPrec [DeleteItem]
ReadPrec DeleteItem
Int -> ReadS DeleteItem
ReadS [DeleteItem]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteItem]
$creadListPrec :: ReadPrec [DeleteItem]
readPrec :: ReadPrec DeleteItem
$creadPrec :: ReadPrec DeleteItem
readList :: ReadS [DeleteItem]
$creadList :: ReadS [DeleteItem]
readsPrec :: Int -> ReadS DeleteItem
$creadsPrec :: Int -> ReadS DeleteItem
Read,Eq DeleteItem
DeleteItem -> DeleteItem -> Bool
DeleteItem -> DeleteItem -> Ordering
DeleteItem -> DeleteItem -> DeleteItem
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 :: DeleteItem -> DeleteItem -> DeleteItem
$cmin :: DeleteItem -> DeleteItem -> DeleteItem
max :: DeleteItem -> DeleteItem -> DeleteItem
$cmax :: DeleteItem -> DeleteItem -> DeleteItem
>= :: DeleteItem -> DeleteItem -> Bool
$c>= :: DeleteItem -> DeleteItem -> Bool
> :: DeleteItem -> DeleteItem -> Bool
$c> :: DeleteItem -> DeleteItem -> Bool
<= :: DeleteItem -> DeleteItem -> Bool
$c<= :: DeleteItem -> DeleteItem -> Bool
< :: DeleteItem -> DeleteItem -> Bool
$c< :: DeleteItem -> DeleteItem -> Bool
compare :: DeleteItem -> DeleteItem -> Ordering
$ccompare :: DeleteItem -> DeleteItem -> Ordering
Ord)


-------------------------------------------------------------------------------
-- | Construct a minimal 'DeleteItem' request.
deleteItem :: T.Text
        -- ^ A Dynamo table name
        -> PrimaryKey
        -- ^ Item to be saved
        -> DeleteItem
deleteItem :: Text -> PrimaryKey -> DeleteItem
deleteItem Text
tn PrimaryKey
key = Text
-> PrimaryKey
-> Conditions
-> UpdateReturn
-> ReturnConsumption
-> ReturnItemCollectionMetrics
-> DeleteItem
DeleteItem Text
tn PrimaryKey
key forall a. Default a => a
def forall a. Default a => a
def forall a. Default a => a
def forall a. Default a => a
def


instance ToJSON DeleteItem where
    toJSON :: DeleteItem -> Value
toJSON DeleteItem{Text
UpdateReturn
ReturnItemCollectionMetrics
ReturnConsumption
Conditions
PrimaryKey
diRetMet :: ReturnItemCollectionMetrics
diRetCons :: ReturnConsumption
diReturn :: UpdateReturn
diExpect :: Conditions
diKey :: PrimaryKey
diTable :: Text
diRetMet :: DeleteItem -> ReturnItemCollectionMetrics
diRetCons :: DeleteItem -> ReturnConsumption
diReturn :: DeleteItem -> UpdateReturn
diExpect :: DeleteItem -> Conditions
diKey :: DeleteItem -> PrimaryKey
diTable :: DeleteItem -> Text
..} =
        [Pair] -> Value
object forall a b. (a -> b) -> a -> b
$ Conditions -> [Pair]
expectsJson Conditions
diExpect forall a. [a] -> [a] -> [a]
++
          [ Key
"TableName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
diTable
          , Key
"Key" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= PrimaryKey
diKey
          , Key
"ReturnValues" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= UpdateReturn
diReturn
          , Key
"ReturnConsumedCapacity" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= ReturnConsumption
diRetCons
          , Key
"ReturnItemCollectionMetrics" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= ReturnItemCollectionMetrics
diRetMet
          ]



data DeleteItemResponse = DeleteItemResponse {
      DeleteItemResponse -> Maybe Item
dirAttrs    :: Maybe Item
    -- ^ Old attributes, if requested
    , DeleteItemResponse -> Maybe ConsumedCapacity
dirConsumed :: Maybe ConsumedCapacity
    -- ^ Amount of capacity consumed
    , DeleteItemResponse -> Maybe ItemCollectionMetrics
dirColMet   :: Maybe ItemCollectionMetrics
    -- ^ Collection metrics if they have been requested.
    } deriving (DeleteItemResponse -> DeleteItemResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteItemResponse -> DeleteItemResponse -> Bool
$c/= :: DeleteItemResponse -> DeleteItemResponse -> Bool
== :: DeleteItemResponse -> DeleteItemResponse -> Bool
$c== :: DeleteItemResponse -> DeleteItemResponse -> Bool
Eq,Int -> DeleteItemResponse -> ShowS
[DeleteItemResponse] -> ShowS
DeleteItemResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteItemResponse] -> ShowS
$cshowList :: [DeleteItemResponse] -> ShowS
show :: DeleteItemResponse -> String
$cshow :: DeleteItemResponse -> String
showsPrec :: Int -> DeleteItemResponse -> ShowS
$cshowsPrec :: Int -> DeleteItemResponse -> ShowS
Show,ReadPrec [DeleteItemResponse]
ReadPrec DeleteItemResponse
Int -> ReadS DeleteItemResponse
ReadS [DeleteItemResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteItemResponse]
$creadListPrec :: ReadPrec [DeleteItemResponse]
readPrec :: ReadPrec DeleteItemResponse
$creadPrec :: ReadPrec DeleteItemResponse
readList :: ReadS [DeleteItemResponse]
$creadList :: ReadS [DeleteItemResponse]
readsPrec :: Int -> ReadS DeleteItemResponse
$creadsPrec :: Int -> ReadS DeleteItemResponse
Read,Eq DeleteItemResponse
DeleteItemResponse -> DeleteItemResponse -> Bool
DeleteItemResponse -> DeleteItemResponse -> Ordering
DeleteItemResponse -> DeleteItemResponse -> DeleteItemResponse
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 :: DeleteItemResponse -> DeleteItemResponse -> DeleteItemResponse
$cmin :: DeleteItemResponse -> DeleteItemResponse -> DeleteItemResponse
max :: DeleteItemResponse -> DeleteItemResponse -> DeleteItemResponse
$cmax :: DeleteItemResponse -> DeleteItemResponse -> DeleteItemResponse
>= :: DeleteItemResponse -> DeleteItemResponse -> Bool
$c>= :: DeleteItemResponse -> DeleteItemResponse -> Bool
> :: DeleteItemResponse -> DeleteItemResponse -> Bool
$c> :: DeleteItemResponse -> DeleteItemResponse -> Bool
<= :: DeleteItemResponse -> DeleteItemResponse -> Bool
$c<= :: DeleteItemResponse -> DeleteItemResponse -> Bool
< :: DeleteItemResponse -> DeleteItemResponse -> Bool
$c< :: DeleteItemResponse -> DeleteItemResponse -> Bool
compare :: DeleteItemResponse -> DeleteItemResponse -> Ordering
$ccompare :: DeleteItemResponse -> DeleteItemResponse -> Ordering
Ord)



instance Transaction DeleteItem DeleteItemResponse


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


instance FromJSON DeleteItemResponse where
    parseJSON :: Value -> Parser DeleteItemResponse
parseJSON (Object Object
v) = Maybe Item
-> Maybe ConsumedCapacity
-> Maybe ItemCollectionMetrics
-> DeleteItemResponse
DeleteItemResponse
        forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"Attributes"
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"ConsumedCapacity"
        forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"ItemCollectionMetrics"
    parseJSON Value
_ = forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"DeleteItemResponse must be an object."


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


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