module Aws.Sqs.Commands.Queue where

import           Aws.Core
import           Aws.Sqs.Core
import           Control.Applicative
import           Data.Maybe
import           Prelude
import           Text.XML.Cursor       (($//), (&/))
import qualified Data.Text             as T
import qualified Data.Text.Encoding    as TE
import qualified Text.XML.Cursor       as Cu
import qualified Data.ByteString.Char8 as B

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

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


instance ResponseConsumer r CreateQueueResponse where
    type ResponseMetadata CreateQueueResponse = SqsMetadata
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata CreateQueueResponse)
-> HTTPResponseConsumer CreateQueueResponse
responseConsumer Request
_ r
_ = (Cursor -> Response SqsMetadata CreateQueueResponse)
-> IORef SqsMetadata -> HTTPResponseConsumer CreateQueueResponse
forall a.
(Cursor -> Response SqsMetadata a)
-> IORef SqsMetadata -> HTTPResponseConsumer a
sqsXmlResponseConsumer Cursor -> Response SqsMetadata CreateQueueResponse
forall {m :: * -> *}.
MonadThrow m =>
Cursor -> m CreateQueueResponse
parse
      where
        parse :: Cursor -> m CreateQueueResponse
parse Cursor
el = do
          Text
url <- String -> [Text] -> m Text
forall (m :: * -> *) a. MonadThrow m => String -> [a] -> m a
force String
"Missing Queue Url" ([Text] -> m Text) -> [Text] -> m Text
forall a b. (a -> b) -> a -> b
$ Cursor
el Cursor -> (Cursor -> [Text]) -> [Text]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$// Text -> Axis
Cu.laxElement Text
"QueueUrl" Axis -> (Cursor -> [Text]) -> Cursor -> [Text]
forall node a.
Axis node -> (Cursor node -> [a]) -> Cursor node -> [a]
&/ Cursor -> [Text]
Cu.content
          CreateQueueResponse -> m CreateQueueResponse
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return CreateQueueResponse{ cqrQueueUrl :: Text
cqrQueueUrl = Text
url}

-- | ServiceConfiguration: 'SqsConfiguration'
instance SignQuery CreateQueue  where
    type ServiceConfiguration CreateQueue  = SqsConfiguration
    signQuery :: forall queryType.
CreateQueue
-> ServiceConfiguration CreateQueue queryType
-> SignatureData
-> SignedQuery
signQuery CreateQueue {Maybe Int
Text
cqDefaultVisibilityTimeout :: CreateQueue -> Maybe Int
cqQueueName :: CreateQueue -> Text
cqDefaultVisibilityTimeout :: Maybe Int
cqQueueName :: Text
..} = SqsQuery
-> SqsConfiguration queryType -> SignatureData -> SignedQuery
forall qt.
SqsQuery -> SqsConfiguration qt -> SignatureData -> SignedQuery
sqsSignQuery SqsQuery {
                                             sqsQueueName :: Maybe QueueName
sqsQueueName = Maybe QueueName
forall a. Maybe a
Nothing,
                                             sqsQuery :: Query
sqsQuery = [(ByteString
"Action", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
"CreateQueue"),
                                                        (ByteString
"QueueName", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString) -> ByteString -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ Text -> ByteString
TE.encodeUtf8 Text
cqQueueName)] Query -> Query -> Query
forall a. [a] -> [a] -> [a]
++
                                                        [Maybe QueryItem] -> Query
forall a. [Maybe a] -> [a]
catMaybes [(ByteString
"DefaultVisibilityTimeout",) (Maybe ByteString -> QueryItem)
-> Maybe (Maybe ByteString) -> Maybe QueryItem
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> case Maybe Int
cqDefaultVisibilityTimeout of
                                                                                                       Just Int
x -> Maybe ByteString -> Maybe (Maybe ByteString)
forall a. a -> Maybe a
Just (Maybe ByteString -> Maybe (Maybe ByteString))
-> Maybe ByteString -> Maybe (Maybe ByteString)
forall a b. (a -> b) -> a -> b
$ ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString) -> ByteString -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ String -> ByteString
B.pack (String -> ByteString) -> String -> ByteString
forall a b. (a -> b) -> a -> b
$ Int -> String
forall a. Show a => a -> String
show Int
x
                                                                                                       Maybe Int
Nothing -> Maybe (Maybe ByteString)
forall a. Maybe a
Nothing]}

instance Transaction CreateQueue CreateQueueResponse

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

data DeleteQueue = DeleteQueue {
    DeleteQueue -> QueueName
dqQueueName :: QueueName 
  } deriving (Int -> DeleteQueue -> ShowS
[DeleteQueue] -> ShowS
DeleteQueue -> String
(Int -> DeleteQueue -> ShowS)
-> (DeleteQueue -> String)
-> ([DeleteQueue] -> ShowS)
-> Show DeleteQueue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DeleteQueue -> ShowS
showsPrec :: Int -> DeleteQueue -> ShowS
$cshow :: DeleteQueue -> String
show :: DeleteQueue -> String
$cshowList :: [DeleteQueue] -> ShowS
showList :: [DeleteQueue] -> ShowS
Show)

data DeleteQueueResponse = DeleteQueueResponse 
  deriving (Int -> DeleteQueueResponse -> ShowS
[DeleteQueueResponse] -> ShowS
DeleteQueueResponse -> String
(Int -> DeleteQueueResponse -> ShowS)
-> (DeleteQueueResponse -> String)
-> ([DeleteQueueResponse] -> ShowS)
-> Show DeleteQueueResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DeleteQueueResponse -> ShowS
showsPrec :: Int -> DeleteQueueResponse -> ShowS
$cshow :: DeleteQueueResponse -> String
show :: DeleteQueueResponse -> String
$cshowList :: [DeleteQueueResponse] -> ShowS
showList :: [DeleteQueueResponse] -> ShowS
Show)

instance ResponseConsumer r DeleteQueueResponse where
    type ResponseMetadata DeleteQueueResponse = SqsMetadata
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata DeleteQueueResponse)
-> HTTPResponseConsumer DeleteQueueResponse
responseConsumer Request
_ r
_ = (Cursor -> Response SqsMetadata DeleteQueueResponse)
-> IORef SqsMetadata -> HTTPResponseConsumer DeleteQueueResponse
forall a.
(Cursor -> Response SqsMetadata a)
-> IORef SqsMetadata -> HTTPResponseConsumer a
sqsXmlResponseConsumer Cursor -> Response SqsMetadata DeleteQueueResponse
forall {m :: * -> *} {p}. Monad m => p -> m DeleteQueueResponse
parse
      where
        parse :: p -> m DeleteQueueResponse
parse p
_ = do DeleteQueueResponse -> m DeleteQueueResponse
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return DeleteQueueResponse{}
          
-- | ServiceConfiguration: 'SqsConfiguration'
instance SignQuery DeleteQueue  where 
    type ServiceConfiguration DeleteQueue  = SqsConfiguration
    signQuery :: forall queryType.
DeleteQueue
-> ServiceConfiguration DeleteQueue queryType
-> SignatureData
-> SignedQuery
signQuery DeleteQueue {QueueName
dqQueueName :: DeleteQueue -> QueueName
dqQueueName :: QueueName
..} = SqsQuery
-> SqsConfiguration queryType -> SignatureData -> SignedQuery
forall qt.
SqsQuery -> SqsConfiguration qt -> SignatureData -> SignedQuery
sqsSignQuery SqsQuery {
                                             sqsQueueName :: Maybe QueueName
sqsQueueName = QueueName -> Maybe QueueName
forall a. a -> Maybe a
Just QueueName
dqQueueName, 
                                             sqsQuery :: Query
sqsQuery = [(ByteString
"Action", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
"DeleteQueue")]}

instance Transaction DeleteQueue DeleteQueueResponse

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

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

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

instance ResponseConsumer r ListQueuesResponse where
    type ResponseMetadata ListQueuesResponse = SqsMetadata
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata ListQueuesResponse)
-> HTTPResponseConsumer ListQueuesResponse
responseConsumer Request
_ r
_ = (Cursor -> Response SqsMetadata ListQueuesResponse)
-> IORef SqsMetadata -> HTTPResponseConsumer ListQueuesResponse
forall a.
(Cursor -> Response SqsMetadata a)
-> IORef SqsMetadata -> HTTPResponseConsumer a
sqsXmlResponseConsumer Cursor -> Response SqsMetadata ListQueuesResponse
forall {m :: * -> *}. Monad m => Cursor -> m ListQueuesResponse
parse
      where
        parse :: Cursor -> m ListQueuesResponse
parse Cursor
el = do
            let queues :: [Text]
queues = Cursor
el Cursor -> (Cursor -> [Text]) -> [Text]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$// Text -> Axis
Cu.laxElement Text
"QueueUrl" Axis -> (Cursor -> [Text]) -> Cursor -> [Text]
forall node a.
Axis node -> (Cursor node -> [a]) -> Cursor node -> [a]
&/ Cursor -> [Text]
Cu.content
            ListQueuesResponse -> m ListQueuesResponse
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ListQueuesResponse { lqrQueueUrls :: [Text]
lqrQueueUrls = [Text]
queues }

-- | ServiceConfiguration: 'SqsConfiguration'
instance SignQuery ListQueues where
    type ServiceConfiguration ListQueues = SqsConfiguration
    signQuery :: forall queryType.
ListQueues
-> ServiceConfiguration ListQueues queryType
-> SignatureData
-> SignedQuery
signQuery ListQueues{Maybe Text
lqQueueNamePrefix :: ListQueues -> Maybe Text
lqQueueNamePrefix :: Maybe Text
..} = SqsQuery
-> SqsConfiguration queryType -> SignatureData -> SignedQuery
forall qt.
SqsQuery -> SqsConfiguration qt -> SignatureData -> SignedQuery
sqsSignQuery SqsQuery {
                                              sqsQueueName :: Maybe QueueName
sqsQueueName = Maybe QueueName
forall a. Maybe a
Nothing,
                                              sqsQuery :: Query
sqsQuery = [(ByteString
"Action", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
"ListQueues")] Query -> Query -> Query
forall a. [a] -> [a] -> [a]
++ [Maybe QueryItem] -> Query
forall a. [Maybe a] -> [a]
catMaybes [
                                              (ByteString
"QueueNamePrefix",) (Maybe ByteString -> QueryItem)
-> Maybe (Maybe ByteString) -> Maybe QueryItem
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> case Maybe Text
lqQueueNamePrefix of
                                                                         Just Text
x  -> Maybe ByteString -> Maybe (Maybe ByteString)
forall a. a -> Maybe a
Just (Maybe ByteString -> Maybe (Maybe ByteString))
-> Maybe ByteString -> Maybe (Maybe ByteString)
forall a b. (a -> b) -> a -> b
$ ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString) -> ByteString -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ Text -> ByteString
TE.encodeUtf8 Text
x
                                                                         Maybe Text
Nothing -> Maybe (Maybe ByteString)
forall a. Maybe a
Nothing]}

instance Transaction ListQueues ListQueuesResponse

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