module Aws.Sqs.Commands.QueueAttributes where

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

data GetQueueAttributes = GetQueueAttributes {
  GetQueueAttributes -> QueueName
gqaQueueName :: QueueName,
  GetQueueAttributes -> [QueueAttribute]
gqaAttributes :: [QueueAttribute]
}deriving (Int -> GetQueueAttributes -> ShowS
[GetQueueAttributes] -> ShowS
GetQueueAttributes -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetQueueAttributes] -> ShowS
$cshowList :: [GetQueueAttributes] -> ShowS
show :: GetQueueAttributes -> String
$cshow :: GetQueueAttributes -> String
showsPrec :: Int -> GetQueueAttributes -> ShowS
$cshowsPrec :: Int -> GetQueueAttributes -> ShowS
Show)

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

parseAttributes :: Cu.Cursor -> [(QueueAttribute, T.Text)]
parseAttributes :: Cursor -> [(QueueAttribute, Text)]
parseAttributes Cursor
el = do
  Text
name <- forall (m :: * -> *) a. MonadThrow m => String -> [a] -> m a
force String
"Missing Name" forall a b. (a -> b) -> a -> b
$ Cursor
el forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Text -> Axis
Cu.laxElement Text
"Name" forall node a.
Axis node -> (Cursor node -> [a]) -> Cursor node -> [a]
&/ Cursor -> [Text]
Cu.content
  Text
value <- forall (m :: * -> *) a. MonadThrow m => String -> [a] -> m a
force String
"Missing Value" forall a b. (a -> b) -> a -> b
$ Cursor
el forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Text -> Axis
Cu.laxElement Text
"Value" forall node a.
Axis node -> (Cursor node -> [a]) -> Cursor node -> [a]
&/ Cursor -> [Text]
Cu.content
  QueueAttribute
parsedName <- forall (m :: * -> *). MonadThrow m => Text -> m QueueAttribute
parseQueueAttribute Text
name
  forall (m :: * -> *) a. Monad m => a -> m a
return (QueueAttribute
parsedName, Text
value)

instance ResponseConsumer r GetQueueAttributesResponse where
    type ResponseMetadata GetQueueAttributesResponse = SqsMetadata
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata GetQueueAttributesResponse)
-> HTTPResponseConsumer GetQueueAttributesResponse
responseConsumer Request
_ r
_ = forall a.
(Cursor -> Response SqsMetadata a)
-> IORef SqsMetadata -> HTTPResponseConsumer a
sqsXmlResponseConsumer forall {m :: * -> *}.
Monad m =>
Cursor -> m GetQueueAttributesResponse
parse
      where
        parse :: Cursor -> m GetQueueAttributesResponse
parse Cursor
el = do
          let attributes :: [(QueueAttribute, Text)]
attributes = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall a b. (a -> b) -> a -> b
$ Cursor
el forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$// Text -> Axis
Cu.laxElement Text
"Attribute" forall node a b.
(Cursor node -> [a]) -> (a -> b) -> Cursor node -> [b]
&| Cursor -> [(QueueAttribute, Text)]
parseAttributes
          forall (m :: * -> *) a. Monad m => a -> m a
return GetQueueAttributesResponse{ gqarAttributes :: [(QueueAttribute, Text)]
gqarAttributes = [(QueueAttribute, Text)]
attributes }

formatAttributes :: [QueueAttribute] -> [(B.ByteString, Maybe B.ByteString)]
formatAttributes :: [QueueAttribute] -> [(ByteString, Maybe ByteString)]
formatAttributes [QueueAttribute]
attrs =
  case forall (t :: * -> *) a. Foldable t => t a -> Int
length [QueueAttribute]
attrs of
    Int
0 -> forall a. HasCallStack => a
undefined
    Int
1 -> [(ByteString
"AttributeName", forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ String -> ByteString
B.pack forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack forall a b. (a -> b) -> a -> b
$ QueueAttribute -> Text
printQueueAttribute forall a b. (a -> b) -> a -> b
$ [QueueAttribute]
attrs forall a. [a] -> Int -> a
!! Int
0)]
    Int
_ -> forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\ QueueAttribute
x Integer
y -> (([ByteString] -> ByteString
B.concat [ByteString
"AttributeName.", String -> ByteString
B.pack forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show forall a b. (a -> b) -> a -> b
$ Integer
y]), forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ String -> ByteString
B.pack forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack forall a b. (a -> b) -> a -> b
$ QueueAttribute -> Text
printQueueAttribute QueueAttribute
x) ) [QueueAttribute]
attrs [Integer
1 :: Integer ..]

-- | ServiceConfiguration: 'SqsConfiguration'
instance SignQuery GetQueueAttributes where
    type ServiceConfiguration GetQueueAttributes = SqsConfiguration
    signQuery :: forall queryType.
GetQueueAttributes
-> ServiceConfiguration GetQueueAttributes queryType
-> SignatureData
-> SignedQuery
signQuery GetQueueAttributes{[QueueAttribute]
QueueName
gqaAttributes :: [QueueAttribute]
gqaQueueName :: QueueName
gqaAttributes :: GetQueueAttributes -> [QueueAttribute]
gqaQueueName :: GetQueueAttributes -> QueueName
..} = forall qt.
SqsQuery -> SqsConfiguration qt -> SignatureData -> SignedQuery
sqsSignQuery SqsQuery {
                                              sqsQueueName :: Maybe QueueName
sqsQueueName = forall a. a -> Maybe a
Just QueueName
gqaQueueName,
                                              sqsQuery :: [(ByteString, Maybe ByteString)]
sqsQuery = [(ByteString
"Action", forall a. a -> Maybe a
Just ByteString
"GetQueueAttributes")] forall a. [a] -> [a] -> [a]
++ ([QueueAttribute] -> [(ByteString, Maybe ByteString)]
formatAttributes [QueueAttribute]
gqaAttributes)}

instance Transaction GetQueueAttributes GetQueueAttributesResponse

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

data SetQueueAttributes = SetQueueAttributes{
  SetQueueAttributes -> QueueAttribute
sqaAttribute :: QueueAttribute,
  SetQueueAttributes -> Text
sqaValue :: T.Text,
  SetQueueAttributes -> QueueName
sqaQueueName :: QueueName 
}deriving (Int -> SetQueueAttributes -> ShowS
[SetQueueAttributes] -> ShowS
SetQueueAttributes -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SetQueueAttributes] -> ShowS
$cshowList :: [SetQueueAttributes] -> ShowS
show :: SetQueueAttributes -> String
$cshow :: SetQueueAttributes -> String
showsPrec :: Int -> SetQueueAttributes -> ShowS
$cshowsPrec :: Int -> SetQueueAttributes -> ShowS
Show)

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

instance ResponseConsumer r SetQueueAttributesResponse where
    type ResponseMetadata SetQueueAttributesResponse = SqsMetadata
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata SetQueueAttributesResponse)
-> HTTPResponseConsumer SetQueueAttributesResponse
responseConsumer Request
_ r
_ = forall a.
(Cursor -> Response SqsMetadata a)
-> IORef SqsMetadata -> HTTPResponseConsumer a
sqsXmlResponseConsumer forall {m :: * -> *} {p}.
Monad m =>
p -> m SetQueueAttributesResponse
parse
      where 
        parse :: p -> m SetQueueAttributesResponse
parse p
_ = do
          forall (m :: * -> *) a. Monad m => a -> m a
return SetQueueAttributesResponse {}
          
-- | ServiceConfiguration: 'SqsConfiguration'
instance SignQuery SetQueueAttributes  where 
    type ServiceConfiguration SetQueueAttributes  = SqsConfiguration
    signQuery :: forall queryType.
SetQueueAttributes
-> ServiceConfiguration SetQueueAttributes queryType
-> SignatureData
-> SignedQuery
signQuery SetQueueAttributes {Text
QueueAttribute
QueueName
sqaQueueName :: QueueName
sqaValue :: Text
sqaAttribute :: QueueAttribute
sqaQueueName :: SetQueueAttributes -> QueueName
sqaValue :: SetQueueAttributes -> Text
sqaAttribute :: SetQueueAttributes -> QueueAttribute
..} = forall qt.
SqsQuery -> SqsConfiguration qt -> SignatureData -> SignedQuery
sqsSignQuery SqsQuery { 
                                             sqsQueueName :: Maybe QueueName
sqsQueueName = forall a. a -> Maybe a
Just QueueName
sqaQueueName,
                                             sqsQuery :: [(ByteString, Maybe ByteString)]
sqsQuery = [(ByteString
"Action", forall a. a -> Maybe a
Just ByteString
"SetQueueAttributes"), 
                                                        (ByteString
"Attribute.Name", forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text -> ByteString
TE.encodeUtf8 forall a b. (a -> b) -> a -> b
$ QueueAttribute -> Text
printQueueAttribute QueueAttribute
sqaAttribute),
                                                        (ByteString
"Attribute.Value", forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text -> ByteString
TE.encodeUtf8 Text
sqaValue)]} 

instance Transaction SetQueueAttributes SetQueueAttributesResponse

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