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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateQueue] -> ShowS
$cshowList :: [CreateQueue] -> ShowS
show :: CreateQueue -> String
$cshow :: CreateQueue -> String
showsPrec :: Int -> CreateQueue -> ShowS
$cshowsPrec :: Int -> CreateQueue -> ShowS
Show)

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


instance ResponseConsumer r CreateQueueResponse where
    type ResponseMetadata CreateQueueResponse = SqsMetadata
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata CreateQueueResponse)
-> HTTPResponseConsumer CreateQueueResponse
responseConsumer Request
_ r
_ = forall a.
(Cursor -> Response SqsMetadata a)
-> IORef SqsMetadata -> HTTPResponseConsumer a
sqsXmlResponseConsumer forall {m :: * -> *}.
MonadThrow m =>
Cursor -> m CreateQueueResponse
parse
      where
        parse :: Cursor -> m CreateQueueResponse
parse Cursor
el = do
          Text
url <- forall (m :: * -> *) a. MonadThrow m => String -> [a] -> m a
force String
"Missing Queue Url" forall a b. (a -> b) -> a -> b
$ Cursor
el forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$// Text -> Axis
Cu.laxElement Text
"QueueUrl" forall node a.
Axis node -> (Cursor node -> [a]) -> Cursor node -> [a]
&/ Cursor -> [Text]
Cu.content
          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
cqQueueName :: Text
cqDefaultVisibilityTimeout :: Maybe Int
cqQueueName :: CreateQueue -> Text
cqDefaultVisibilityTimeout :: CreateQueue -> Maybe Int
..} = forall qt.
SqsQuery -> SqsConfiguration qt -> SignatureData -> SignedQuery
sqsSignQuery SqsQuery {
                                             sqsQueueName :: Maybe QueueName
sqsQueueName = forall a. Maybe a
Nothing,
                                             sqsQuery :: Query
sqsQuery = [(ByteString
"Action", forall a. a -> Maybe a
Just ByteString
"CreateQueue"),
                                                        (ByteString
"QueueName", forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text -> ByteString
TE.encodeUtf8 Text
cqQueueName)] forall a. [a] -> [a] -> [a]
++
                                                        forall a. [Maybe a] -> [a]
catMaybes [(ByteString
"DefaultVisibilityTimeout",) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> case Maybe Int
cqDefaultVisibilityTimeout of
                                                                                                       Just Int
x -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ String -> ByteString
B.pack forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show Int
x
                                                                                                       Maybe Int
Nothing -> forall a. Maybe a
Nothing]}

instance Transaction CreateQueue CreateQueueResponse

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

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

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

instance ResponseConsumer r DeleteQueueResponse where
    type ResponseMetadata DeleteQueueResponse = SqsMetadata
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata DeleteQueueResponse)
-> HTTPResponseConsumer DeleteQueueResponse
responseConsumer Request
_ r
_ = forall a.
(Cursor -> Response SqsMetadata a)
-> IORef SqsMetadata -> HTTPResponseConsumer a
sqsXmlResponseConsumer forall {m :: * -> *} {p}. Monad m => p -> m DeleteQueueResponse
parse
      where
        parse :: p -> m DeleteQueueResponse
parse p
_ = do 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 :: QueueName
dqQueueName :: DeleteQueue -> QueueName
..} = forall qt.
SqsQuery -> SqsConfiguration qt -> SignatureData -> SignedQuery
sqsSignQuery SqsQuery {
                                             sqsQueueName :: Maybe QueueName
sqsQueueName = forall a. a -> Maybe a
Just QueueName
dqQueueName, 
                                             sqsQuery :: Query
sqsQuery = [(ByteString
"Action", 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 = 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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListQueues] -> ShowS
$cshowList :: [ListQueues] -> ShowS
show :: ListQueues -> String
$cshow :: ListQueues -> String
showsPrec :: Int -> ListQueues -> ShowS
$cshowsPrec :: Int -> ListQueues -> ShowS
Show)

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

instance ResponseConsumer r ListQueuesResponse where
    type ResponseMetadata ListQueuesResponse = SqsMetadata
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata ListQueuesResponse)
-> HTTPResponseConsumer ListQueuesResponse
responseConsumer Request
_ r
_ = forall a.
(Cursor -> Response SqsMetadata a)
-> IORef SqsMetadata -> HTTPResponseConsumer a
sqsXmlResponseConsumer forall {m :: * -> *}. Monad m => Cursor -> m ListQueuesResponse
parse
      where
        parse :: Cursor -> m ListQueuesResponse
parse Cursor
el = do
            let queues :: [Text]
queues = Cursor
el forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$// Text -> Axis
Cu.laxElement Text
"QueueUrl" forall node a.
Axis node -> (Cursor node -> [a]) -> Cursor node -> [a]
&/ Cursor -> [Text]
Cu.content
            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 :: Maybe Text
lqQueueNamePrefix :: ListQueues -> Maybe Text
..} = forall qt.
SqsQuery -> SqsConfiguration qt -> SignatureData -> SignedQuery
sqsSignQuery SqsQuery {
                                              sqsQueueName :: Maybe QueueName
sqsQueueName = forall a. Maybe a
Nothing,
                                              sqsQuery :: Query
sqsQuery = [(ByteString
"Action", forall a. a -> Maybe a
Just ByteString
"ListQueues")] forall a. [a] -> [a] -> [a]
++ forall a. [Maybe a] -> [a]
catMaybes [
                                              (ByteString
"QueueNamePrefix",) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> case Maybe Text
lqQueueNamePrefix of
                                                                         Just Text
x  -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text -> ByteString
TE.encodeUtf8 Text
x
                                                                         Maybe Text
Nothing -> forall a. Maybe a
Nothing]}

instance Transaction ListQueues ListQueuesResponse

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