module Aws.Sqs.Commands.Permission where

import           Aws.Core
import           Aws.Sqs.Core
import qualified Data.ByteString.Char8 as B
import qualified Data.Text             as T
import qualified Data.Text.Encoding    as TE
import qualified Network.HTTP.Types    as HTTP

data AddPermission = AddPermission {
    AddPermission -> Text
apLabel :: T.Text,
    AddPermission -> [(Text, SqsPermission)]
apPermissions :: [(T.Text,SqsPermission)],
    AddPermission -> QueueName
apQueueName :: QueueName
  } deriving (Int -> AddPermission -> ShowS
[AddPermission] -> ShowS
AddPermission -> String
(Int -> AddPermission -> ShowS)
-> (AddPermission -> String)
-> ([AddPermission] -> ShowS)
-> Show AddPermission
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AddPermission] -> ShowS
$cshowList :: [AddPermission] -> ShowS
show :: AddPermission -> String
$cshow :: AddPermission -> String
showsPrec :: Int -> AddPermission -> ShowS
$cshowsPrec :: Int -> AddPermission -> ShowS
Show)

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


formatPermissions :: [(T.Text,SqsPermission)] -> [HTTP.QueryItem]
formatPermissions :: [(Text, SqsPermission)] -> [QueryItem]
formatPermissions [(Text, SqsPermission)]
perms = 
  [[QueryItem]] -> [QueryItem]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[QueryItem]] -> [QueryItem]) -> [[QueryItem]] -> [QueryItem]
forall a b. (a -> b) -> a -> b
$ ((Text, SqsPermission) -> Integer -> [QueryItem])
-> [(Text, SqsPermission)] -> [Integer] -> [[QueryItem]]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith(\ (Text, SqsPermission)
x Integer
y -> [(String -> ByteString
B.pack (String -> ByteString) -> String -> ByteString
forall a b. (a -> b) -> a -> b
$ String
"AwsAccountId." String -> ShowS
forall a. [a] -> [a] -> [a]
++ Integer -> String
forall a. Show a => a -> String
show Integer
y, 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
$ Text -> String
T.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ (Text, SqsPermission) -> Text
forall a b. (a, b) -> a
fst (Text, SqsPermission)
x), 
                             (String -> ByteString
B.pack (String -> ByteString) -> String -> ByteString
forall a b. (a -> b) -> a -> b
$ String
"ActionName." String -> ShowS
forall a. [a] -> [a] -> [a]
++ Integer -> String
forall a. Show a => a -> String
show Integer
y, 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
$ Text -> String
T.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ SqsPermission -> Text
printPermission (SqsPermission -> Text) -> SqsPermission -> Text
forall a b. (a -> b) -> a -> b
$ (Text, SqsPermission) -> SqsPermission
forall a b. (a, b) -> b
snd (Text, SqsPermission)
x)]) [(Text, SqsPermission)]
perms [Integer
1 :: Integer ..]

instance ResponseConsumer r AddPermissionResponse where
    type ResponseMetadata AddPermissionResponse = SqsMetadata
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata AddPermissionResponse)
-> HTTPResponseConsumer AddPermissionResponse
responseConsumer Request
_ r
_ = (Cursor -> Response SqsMetadata AddPermissionResponse)
-> IORef SqsMetadata -> HTTPResponseConsumer AddPermissionResponse
forall a.
(Cursor -> Response SqsMetadata a)
-> IORef SqsMetadata -> HTTPResponseConsumer a
sqsXmlResponseConsumer Cursor -> Response SqsMetadata AddPermissionResponse
forall (m :: * -> *) p. Monad m => p -> m AddPermissionResponse
parse
       where
         parse :: p -> m AddPermissionResponse
parse p
_ = do
           AddPermissionResponse -> m AddPermissionResponse
forall (m :: * -> *) a. Monad m => a -> m a
return AddPermissionResponse :: AddPermissionResponse
AddPermissionResponse {}
        
-- | ServiceConfiguration: 'SqsConfiguration'
instance SignQuery AddPermission  where 
    type ServiceConfiguration AddPermission  = SqsConfiguration
    signQuery :: AddPermission
-> ServiceConfiguration AddPermission queryType
-> SignatureData
-> SignedQuery
signQuery AddPermission {[(Text, SqsPermission)]
Text
QueueName
apQueueName :: QueueName
apPermissions :: [(Text, SqsPermission)]
apLabel :: Text
apQueueName :: AddPermission -> QueueName
apPermissions :: AddPermission -> [(Text, SqsPermission)]
apLabel :: AddPermission -> Text
..} = SqsQuery
-> SqsConfiguration queryType -> SignatureData -> SignedQuery
forall qt.
SqsQuery -> SqsConfiguration qt -> SignatureData -> SignedQuery
sqsSignQuery SqsQuery :: Maybe QueueName -> [QueryItem] -> SqsQuery
SqsQuery {
                                             sqsQueueName :: Maybe QueueName
sqsQueueName = QueueName -> Maybe QueueName
forall a. a -> Maybe a
Just QueueName
apQueueName, 
                                             sqsQuery :: [QueryItem]
sqsQuery = [(ByteString
"Action", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
"AddPermission"), 
                                                        (ByteString
"QueueName", 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
$ Text -> String
T.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ QueueName -> Text
printQueueName QueueName
apQueueName),
                                                        (ByteString
"Label", 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
$ Text -> String
T.unpack Text
apLabel)] [QueryItem] -> [QueryItem] -> [QueryItem]
forall a. [a] -> [a] -> [a]
++ [(Text, SqsPermission)] -> [QueryItem]
formatPermissions [(Text, SqsPermission)]
apPermissions}

instance Transaction AddPermission AddPermissionResponse

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

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

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

instance ResponseConsumer r RemovePermissionResponse where
    type ResponseMetadata RemovePermissionResponse = SqsMetadata
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata RemovePermissionResponse)
-> HTTPResponseConsumer RemovePermissionResponse
responseConsumer Request
_ r
_ = (Cursor -> Response SqsMetadata RemovePermissionResponse)
-> IORef SqsMetadata
-> HTTPResponseConsumer RemovePermissionResponse
forall a.
(Cursor -> Response SqsMetadata a)
-> IORef SqsMetadata -> HTTPResponseConsumer a
sqsXmlResponseConsumer Cursor -> Response SqsMetadata RemovePermissionResponse
forall (m :: * -> *) p. Monad m => p -> m RemovePermissionResponse
parse
      where 
        parse :: p -> m RemovePermissionResponse
parse p
_ = do
          RemovePermissionResponse -> m RemovePermissionResponse
forall (m :: * -> *) a. Monad m => a -> m a
return RemovePermissionResponse :: RemovePermissionResponse
RemovePermissionResponse {}  
          
-- | ServiceConfiguration: 'SqsConfiguration'
instance SignQuery RemovePermission  where 
    type ServiceConfiguration RemovePermission  = SqsConfiguration
    signQuery :: RemovePermission
-> ServiceConfiguration RemovePermission queryType
-> SignatureData
-> SignedQuery
signQuery RemovePermission {Text
QueueName
rpQueueName :: QueueName
rpLabel :: Text
rpQueueName :: RemovePermission -> QueueName
rpLabel :: RemovePermission -> Text
..} = SqsQuery
-> SqsConfiguration queryType -> SignatureData -> SignedQuery
forall qt.
SqsQuery -> SqsConfiguration qt -> SignatureData -> SignedQuery
sqsSignQuery SqsQuery :: Maybe QueueName -> [QueryItem] -> SqsQuery
SqsQuery {
                                             sqsQueueName :: Maybe QueueName
sqsQueueName = QueueName -> Maybe QueueName
forall a. a -> Maybe a
Just QueueName
rpQueueName, 
                                             sqsQuery :: [QueryItem]
sqsQuery = [(ByteString
"Action", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
"RemovePermission"), 
                                                        (ByteString
"Label", 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
rpLabel )]} 

instance Transaction RemovePermission RemovePermissionResponse

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