module Aws.SimpleDb.Commands.Domain where

import           Aws.Core
import           Aws.SimpleDb.Core
import           Control.Applicative
import           Data.Maybe
import           Data.Time
import           Data.Time.Clock.POSIX
import           Prelude
import           Text.XML.Cursor       (($//), (&|))
import qualified Data.Text             as T
import qualified Data.Text.Encoding    as T

data CreateDomain
    = CreateDomain {
        CreateDomain -> Text
cdDomainName :: T.Text
      }
    deriving (Int -> CreateDomain -> ShowS
[CreateDomain] -> ShowS
CreateDomain -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateDomain] -> ShowS
$cshowList :: [CreateDomain] -> ShowS
show :: CreateDomain -> String
$cshow :: CreateDomain -> String
showsPrec :: Int -> CreateDomain -> ShowS
$cshowsPrec :: Int -> CreateDomain -> ShowS
Show)

data CreateDomainResponse 
    = CreateDomainResponse
    deriving (Int -> CreateDomainResponse -> ShowS
[CreateDomainResponse] -> ShowS
CreateDomainResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateDomainResponse] -> ShowS
$cshowList :: [CreateDomainResponse] -> ShowS
show :: CreateDomainResponse -> String
$cshow :: CreateDomainResponse -> String
showsPrec :: Int -> CreateDomainResponse -> ShowS
$cshowsPrec :: Int -> CreateDomainResponse -> ShowS
Show)
             
createDomain :: T.Text -> CreateDomain
createDomain :: Text -> CreateDomain
createDomain Text
name = CreateDomain { cdDomainName :: Text
cdDomainName = Text
name }
             
-- | ServiceConfiguration: 'SdbConfiguration'
instance SignQuery CreateDomain where
    type ServiceConfiguration CreateDomain = SdbConfiguration
    signQuery :: forall queryType.
CreateDomain
-> ServiceConfiguration CreateDomain queryType
-> SignatureData
-> SignedQuery
signQuery CreateDomain{Text
cdDomainName :: Text
cdDomainName :: CreateDomain -> Text
..} = forall qt.
[(ByteString, ByteString)]
-> SdbConfiguration qt -> SignatureData -> SignedQuery
sdbSignQuery [(ByteString
"Action", ByteString
"CreateDomain"), (ByteString
"DomainName", Text -> ByteString
T.encodeUtf8 Text
cdDomainName)]

instance ResponseConsumer r CreateDomainResponse where
    type ResponseMetadata CreateDomainResponse = SdbMetadata
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata CreateDomainResponse)
-> HTTPResponseConsumer CreateDomainResponse
responseConsumer Request
_ r
_
        = forall a.
(Cursor -> Response SdbMetadata a)
-> IORef SdbMetadata -> HTTPResponseConsumer a
sdbResponseConsumer forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadThrow m => a -> Text -> Cursor -> m a
sdbCheckResponseType CreateDomainResponse
CreateDomainResponse Text
"CreateDomainResponse"

instance Transaction CreateDomain CreateDomainResponse

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

data DeleteDomain
    = DeleteDomain {
        DeleteDomain -> Text
ddDomainName :: T.Text
      }
    deriving (Int -> DeleteDomain -> ShowS
[DeleteDomain] -> ShowS
DeleteDomain -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteDomain] -> ShowS
$cshowList :: [DeleteDomain] -> ShowS
show :: DeleteDomain -> String
$cshow :: DeleteDomain -> String
showsPrec :: Int -> DeleteDomain -> ShowS
$cshowsPrec :: Int -> DeleteDomain -> ShowS
Show)

data DeleteDomainResponse
    = DeleteDomainResponse
    deriving (Int -> DeleteDomainResponse -> ShowS
[DeleteDomainResponse] -> ShowS
DeleteDomainResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteDomainResponse] -> ShowS
$cshowList :: [DeleteDomainResponse] -> ShowS
show :: DeleteDomainResponse -> String
$cshow :: DeleteDomainResponse -> String
showsPrec :: Int -> DeleteDomainResponse -> ShowS
$cshowsPrec :: Int -> DeleteDomainResponse -> ShowS
Show)
             
deleteDomain :: T.Text -> DeleteDomain
deleteDomain :: Text -> DeleteDomain
deleteDomain Text
name = DeleteDomain { ddDomainName :: Text
ddDomainName = Text
name }
             
-- | ServiceConfiguration: 'SdbConfiguration'
instance SignQuery DeleteDomain where
    type ServiceConfiguration DeleteDomain = SdbConfiguration
    signQuery :: forall queryType.
DeleteDomain
-> ServiceConfiguration DeleteDomain queryType
-> SignatureData
-> SignedQuery
signQuery DeleteDomain{Text
ddDomainName :: Text
ddDomainName :: DeleteDomain -> Text
..} = forall qt.
[(ByteString, ByteString)]
-> SdbConfiguration qt -> SignatureData -> SignedQuery
sdbSignQuery [(ByteString
"Action", ByteString
"DeleteDomain"), (ByteString
"DomainName", Text -> ByteString
T.encodeUtf8 Text
ddDomainName)]

instance ResponseConsumer r DeleteDomainResponse where
    type ResponseMetadata DeleteDomainResponse = SdbMetadata
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata DeleteDomainResponse)
-> HTTPResponseConsumer DeleteDomainResponse
responseConsumer Request
_ r
_
        = forall a.
(Cursor -> Response SdbMetadata a)
-> IORef SdbMetadata -> HTTPResponseConsumer a
sdbResponseConsumer forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadThrow m => a -> Text -> Cursor -> m a
sdbCheckResponseType DeleteDomainResponse
DeleteDomainResponse Text
"DeleteDomainResponse"

instance Transaction DeleteDomain DeleteDomainResponse

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

data DomainMetadata
    = DomainMetadata {
        DomainMetadata -> Text
dmDomainName :: T.Text
      }
    deriving (Int -> DomainMetadata -> ShowS
[DomainMetadata] -> ShowS
DomainMetadata -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DomainMetadata] -> ShowS
$cshowList :: [DomainMetadata] -> ShowS
show :: DomainMetadata -> String
$cshow :: DomainMetadata -> String
showsPrec :: Int -> DomainMetadata -> ShowS
$cshowsPrec :: Int -> DomainMetadata -> ShowS
Show)

data DomainMetadataResponse
    = DomainMetadataResponse {
        DomainMetadataResponse -> UTCTime
dmrTimestamp :: UTCTime
      , DomainMetadataResponse -> Integer
dmrItemCount :: Integer
      , DomainMetadataResponse -> Integer
dmrAttributeValueCount :: Integer
      , DomainMetadataResponse -> Integer
dmrAttributeNameCount :: Integer
      , DomainMetadataResponse -> Integer
dmrItemNamesSizeBytes :: Integer
      , DomainMetadataResponse -> Integer
dmrAttributeValuesSizeBytes :: Integer
      , DomainMetadataResponse -> Integer
dmrAttributeNamesSizeBytes :: Integer
      }
    deriving (Int -> DomainMetadataResponse -> ShowS
[DomainMetadataResponse] -> ShowS
DomainMetadataResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DomainMetadataResponse] -> ShowS
$cshowList :: [DomainMetadataResponse] -> ShowS
show :: DomainMetadataResponse -> String
$cshow :: DomainMetadataResponse -> String
showsPrec :: Int -> DomainMetadataResponse -> ShowS
$cshowsPrec :: Int -> DomainMetadataResponse -> ShowS
Show)

domainMetadata :: T.Text -> DomainMetadata
domainMetadata :: Text -> DomainMetadata
domainMetadata Text
name = DomainMetadata { dmDomainName :: Text
dmDomainName = Text
name }

-- | ServiceConfiguration: 'SdbConfiguration'
instance SignQuery DomainMetadata where
    type ServiceConfiguration DomainMetadata = SdbConfiguration
    signQuery :: forall queryType.
DomainMetadata
-> ServiceConfiguration DomainMetadata queryType
-> SignatureData
-> SignedQuery
signQuery DomainMetadata{Text
dmDomainName :: Text
dmDomainName :: DomainMetadata -> Text
..} = forall qt.
[(ByteString, ByteString)]
-> SdbConfiguration qt -> SignatureData -> SignedQuery
sdbSignQuery [(ByteString
"Action", ByteString
"DomainMetadata"), (ByteString
"DomainName", Text -> ByteString
T.encodeUtf8 Text
dmDomainName)]

instance ResponseConsumer r DomainMetadataResponse where
    type ResponseMetadata DomainMetadataResponse = SdbMetadata

    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata DomainMetadataResponse)
-> HTTPResponseConsumer DomainMetadataResponse
responseConsumer Request
_ r
_
        = forall a.
(Cursor -> Response SdbMetadata a)
-> IORef SdbMetadata -> HTTPResponseConsumer a
sdbResponseConsumer forall {m :: * -> *}.
MonadThrow m =>
Cursor -> m DomainMetadataResponse
parse
        where parse :: Cursor -> m DomainMetadataResponse
parse Cursor
cursor = do
                forall (m :: * -> *) a. MonadThrow m => a -> Text -> Cursor -> m a
sdbCheckResponseType () Text
"DomainMetadataResponse" Cursor
cursor
                UTCTime
dmrTimestamp <- forall (m :: * -> *) a. MonadThrow m => String -> [m a] -> m a
forceM String
"Timestamp expected" forall a b. (a -> b) -> a -> b
$ Cursor
cursor forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$// Text -> Cursor -> [String]
elCont Text
"Timestamp" forall node a b.
(Cursor node -> [a]) -> (a -> b) -> Cursor node -> [b]
&| (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap POSIXTime -> UTCTime
posixSecondsToUTCTime forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. (MonadThrow m, Num a) => String -> m a
readInt)
                Integer
dmrItemCount <- forall (m :: * -> *) a. MonadThrow m => String -> [m a] -> m a
forceM String
"ItemCount expected" forall a b. (a -> b) -> a -> b
$ Cursor
cursor forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$// Text -> Cursor -> [String]
elCont Text
"ItemCount" forall node a b.
(Cursor node -> [a]) -> (a -> b) -> Cursor node -> [b]
&| forall (m :: * -> *) a. (MonadThrow m, Num a) => String -> m a
readInt
                Integer
dmrAttributeValueCount <- forall (m :: * -> *) a. MonadThrow m => String -> [m a] -> m a
forceM String
"AttributeValueCount expected" forall a b. (a -> b) -> a -> b
$ Cursor
cursor forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$// Text -> Cursor -> [String]
elCont Text
"AttributeValueCount" forall node a b.
(Cursor node -> [a]) -> (a -> b) -> Cursor node -> [b]
&| forall (m :: * -> *) a. (MonadThrow m, Num a) => String -> m a
readInt
                Integer
dmrAttributeNameCount <- forall (m :: * -> *) a. MonadThrow m => String -> [m a] -> m a
forceM String
"AttributeNameCount expected" forall a b. (a -> b) -> a -> b
$ Cursor
cursor forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$// Text -> Cursor -> [String]
elCont Text
"AttributeNameCount" forall node a b.
(Cursor node -> [a]) -> (a -> b) -> Cursor node -> [b]
&| forall (m :: * -> *) a. (MonadThrow m, Num a) => String -> m a
readInt
                Integer
dmrItemNamesSizeBytes <- forall (m :: * -> *) a. MonadThrow m => String -> [m a] -> m a
forceM String
"ItemNamesSizeBytes expected" forall a b. (a -> b) -> a -> b
$ Cursor
cursor forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$// Text -> Cursor -> [String]
elCont Text
"ItemNamesSizeBytes" forall node a b.
(Cursor node -> [a]) -> (a -> b) -> Cursor node -> [b]
&| forall (m :: * -> *) a. (MonadThrow m, Num a) => String -> m a
readInt
                Integer
dmrAttributeValuesSizeBytes <- forall (m :: * -> *) a. MonadThrow m => String -> [m a] -> m a
forceM String
"AttributeValuesSizeBytes expected" forall a b. (a -> b) -> a -> b
$ Cursor
cursor forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$// Text -> Cursor -> [String]
elCont Text
"AttributeValuesSizeBytes" forall node a b.
(Cursor node -> [a]) -> (a -> b) -> Cursor node -> [b]
&| forall (m :: * -> *) a. (MonadThrow m, Num a) => String -> m a
readInt
                Integer
dmrAttributeNamesSizeBytes <- forall (m :: * -> *) a. MonadThrow m => String -> [m a] -> m a
forceM String
"AttributeNamesSizeBytes expected" forall a b. (a -> b) -> a -> b
$ Cursor
cursor forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$// Text -> Cursor -> [String]
elCont Text
"AttributeNamesSizeBytes" forall node a b.
(Cursor node -> [a]) -> (a -> b) -> Cursor node -> [b]
&| forall (m :: * -> *) a. (MonadThrow m, Num a) => String -> m a
readInt
                forall (m :: * -> *) a. Monad m => a -> m a
return DomainMetadataResponse{Integer
UTCTime
dmrAttributeNamesSizeBytes :: Integer
dmrAttributeValuesSizeBytes :: Integer
dmrItemNamesSizeBytes :: Integer
dmrAttributeNameCount :: Integer
dmrAttributeValueCount :: Integer
dmrItemCount :: Integer
dmrTimestamp :: UTCTime
dmrAttributeNamesSizeBytes :: Integer
dmrAttributeValuesSizeBytes :: Integer
dmrItemNamesSizeBytes :: Integer
dmrAttributeNameCount :: Integer
dmrAttributeValueCount :: Integer
dmrItemCount :: Integer
dmrTimestamp :: UTCTime
..}

instance Transaction DomainMetadata DomainMetadataResponse

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

data ListDomains
    = ListDomains {
        ListDomains -> Maybe Int
ldMaxNumberOfDomains :: Maybe Int
      , ListDomains -> Maybe Text
ldNextToken :: Maybe T.Text
      }
    deriving (Int -> ListDomains -> ShowS
[ListDomains] -> ShowS
ListDomains -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListDomains] -> ShowS
$cshowList :: [ListDomains] -> ShowS
show :: ListDomains -> String
$cshow :: ListDomains -> String
showsPrec :: Int -> ListDomains -> ShowS
$cshowsPrec :: Int -> ListDomains -> ShowS
Show)

data ListDomainsResponse
    = ListDomainsResponse {
        ListDomainsResponse -> [Text]
ldrDomainNames :: [T.Text]
      , ListDomainsResponse -> Maybe Text
ldrNextToken :: Maybe T.Text
      }
    deriving (Int -> ListDomainsResponse -> ShowS
[ListDomainsResponse] -> ShowS
ListDomainsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListDomainsResponse] -> ShowS
$cshowList :: [ListDomainsResponse] -> ShowS
show :: ListDomainsResponse -> String
$cshow :: ListDomainsResponse -> String
showsPrec :: Int -> ListDomainsResponse -> ShowS
$cshowsPrec :: Int -> ListDomainsResponse -> ShowS
Show)

listDomains :: ListDomains
listDomains :: ListDomains
listDomains = ListDomains { ldMaxNumberOfDomains :: Maybe Int
ldMaxNumberOfDomains = forall a. Maybe a
Nothing, ldNextToken :: Maybe Text
ldNextToken = forall a. Maybe a
Nothing }

-- | ServiceConfiguration: 'SdbConfiguration'
instance SignQuery ListDomains where
    type ServiceConfiguration ListDomains = SdbConfiguration
    signQuery :: forall queryType.
ListDomains
-> ServiceConfiguration ListDomains queryType
-> SignatureData
-> SignedQuery
signQuery ListDomains{Maybe Int
Maybe Text
ldNextToken :: Maybe Text
ldMaxNumberOfDomains :: Maybe Int
ldNextToken :: ListDomains -> Maybe Text
ldMaxNumberOfDomains :: ListDomains -> Maybe Int
..} = forall qt.
[(ByteString, ByteString)]
-> SdbConfiguration qt -> SignatureData -> SignedQuery
sdbSignQuery forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
catMaybes [
                                  forall a. a -> Maybe a
Just (ByteString
"Action", ByteString
"ListDomains")
                                , (ByteString
"MaxNumberOfDomains",) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
T.encodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Int
ldMaxNumberOfDomains
                                , (ByteString
"NextToken",) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
T.encodeUtf8 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
ldNextToken
                                ]

instance ResponseConsumer r ListDomainsResponse where
    type ResponseMetadata ListDomainsResponse = SdbMetadata
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata ListDomainsResponse)
-> HTTPResponseConsumer ListDomainsResponse
responseConsumer Request
_ r
_ = forall a.
(Cursor -> Response SdbMetadata a)
-> IORef SdbMetadata -> HTTPResponseConsumer a
sdbResponseConsumer forall {m :: * -> *}.
MonadThrow m =>
Cursor -> m ListDomainsResponse
parse
        where parse :: Cursor -> m ListDomainsResponse
parse Cursor
cursor = do
                forall (m :: * -> *) a. MonadThrow m => a -> Text -> Cursor -> m a
sdbCheckResponseType () Text
"ListDomainsResponse" Cursor
cursor
                let names :: [Text]
names = Cursor
cursor forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$// Text -> Cursor -> [Text]
elContent Text
"DomainName"
                let nextToken :: Maybe Text
nextToken = forall a. [a] -> Maybe a
listToMaybe forall a b. (a -> b) -> a -> b
$ Cursor
cursor forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$// Text -> Cursor -> [Text]
elContent Text
"NextToken"
                forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [Text] -> Maybe Text -> ListDomainsResponse
ListDomainsResponse [Text]
names Maybe Text
nextToken

instance Transaction ListDomains ListDomainsResponse

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

instance ListResponse ListDomainsResponse T.Text where
    listResponse :: ListDomainsResponse -> [Text]
listResponse = ListDomainsResponse -> [Text]
ldrDomainNames

instance IteratedTransaction ListDomains ListDomainsResponse where
  nextIteratedRequest :: ListDomains -> ListDomainsResponse -> Maybe ListDomains
nextIteratedRequest ListDomains
req ListDomainsResponse{ldrNextToken :: ListDomainsResponse -> Maybe Text
ldrNextToken=Maybe Text
nt} = ListDomains
req{ldNextToken :: Maybe Text
ldNextToken=Maybe Text
nt} forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Maybe Text
nt
  --combineIteratedResponse (ListDomainsResponse dn1 _) (ListDomainsResponse dn2 nt2) = ListDomainsResponse (dn1 ++ dn2) nt2