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

data AddPermissionResponse = AddPermissionResponse
  deriving (Int -> AddPermissionResponse -> ShowS
[AddPermissionResponse] -> ShowS
AddPermissionResponse -> [Char]
(Int -> AddPermissionResponse -> ShowS)
-> (AddPermissionResponse -> [Char])
-> ([AddPermissionResponse] -> ShowS)
-> Show AddPermissionResponse
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AddPermissionResponse -> ShowS
showsPrec :: Int -> AddPermissionResponse -> ShowS
$cshow :: AddPermissionResponse -> [Char]
show :: AddPermissionResponse -> [Char]
$cshowList :: [AddPermissionResponse] -> ShowS
showList :: [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 -> [([Char] -> ByteString
B.pack ([Char] -> ByteString) -> [Char] -> ByteString
forall a b. (a -> b) -> a -> b
$ [Char]
"AwsAccountId." [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ Integer -> [Char]
forall a. Show a => a -> [Char]
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
$ [Char] -> ByteString
B.pack ([Char] -> ByteString) -> [Char] -> ByteString
forall a b. (a -> b) -> a -> b
$ Text -> [Char]
T.unpack (Text -> [Char]) -> Text -> [Char]
forall a b. (a -> b) -> a -> b
$ (Text, SqsPermission) -> Text
forall a b. (a, b) -> a
fst (Text, SqsPermission)
x), 
                             ([Char] -> ByteString
B.pack ([Char] -> ByteString) -> [Char] -> ByteString
forall a b. (a -> b) -> a -> b
$ [Char]
"ActionName." [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ Integer -> [Char]
forall a. Show a => a -> [Char]
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
$ [Char] -> ByteString
B.pack ([Char] -> ByteString) -> [Char] -> ByteString
forall a b. (a -> b) -> a -> b
$ Text -> [Char]
T.unpack (Text -> [Char]) -> Text -> [Char]
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 a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return AddPermissionResponse {}
        
-- | ServiceConfiguration: 'SqsConfiguration'
instance SignQuery AddPermission  where 
    type ServiceConfiguration AddPermission  = SqsConfiguration
    signQuery :: forall queryType.
AddPermission
-> ServiceConfiguration AddPermission queryType
-> SignatureData
-> SignedQuery
signQuery AddPermission {[(Text, SqsPermission)]
Text
QueueName
apLabel :: AddPermission -> Text
apPermissions :: AddPermission -> [(Text, SqsPermission)]
apQueueName :: AddPermission -> QueueName
apLabel :: Text
apPermissions :: [(Text, SqsPermission)]
apQueueName :: 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
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
$ [Char] -> ByteString
B.pack ([Char] -> ByteString) -> [Char] -> ByteString
forall a b. (a -> b) -> a -> b
$ Text -> [Char]
T.unpack (Text -> [Char]) -> Text -> [Char]
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
$ [Char] -> ByteString
B.pack ([Char] -> ByteString) -> [Char] -> ByteString
forall a b. (a -> b) -> a -> b
$ Text -> [Char]
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)
AddPermissionResponse -> ResourceT IO AddPermissionResponse
forall a. a -> ResourceT IO a
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 -> [Char]
(Int -> RemovePermission -> ShowS)
-> (RemovePermission -> [Char])
-> ([RemovePermission] -> ShowS)
-> Show RemovePermission
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RemovePermission -> ShowS
showsPrec :: Int -> RemovePermission -> ShowS
$cshow :: RemovePermission -> [Char]
show :: RemovePermission -> [Char]
$cshowList :: [RemovePermission] -> ShowS
showList :: [RemovePermission] -> ShowS
Show)

data RemovePermissionResponse = RemovePermissionResponse 
  deriving (Int -> RemovePermissionResponse -> ShowS
[RemovePermissionResponse] -> ShowS
RemovePermissionResponse -> [Char]
(Int -> RemovePermissionResponse -> ShowS)
-> (RemovePermissionResponse -> [Char])
-> ([RemovePermissionResponse] -> ShowS)
-> Show RemovePermissionResponse
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RemovePermissionResponse -> ShowS
showsPrec :: Int -> RemovePermissionResponse -> ShowS
$cshow :: RemovePermissionResponse -> [Char]
show :: RemovePermissionResponse -> [Char]
$cshowList :: [RemovePermissionResponse] -> ShowS
showList :: [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 a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return RemovePermissionResponse {}  
          
-- | ServiceConfiguration: 'SqsConfiguration'
instance SignQuery RemovePermission  where 
    type ServiceConfiguration RemovePermission  = SqsConfiguration
    signQuery :: forall queryType.
RemovePermission
-> ServiceConfiguration RemovePermission queryType
-> SignatureData
-> SignedQuery
signQuery RemovePermission {Text
QueueName
rpLabel :: RemovePermission -> Text
rpQueueName :: RemovePermission -> QueueName
rpLabel :: Text
rpQueueName :: 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
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)
RemovePermissionResponse -> ResourceT IO RemovePermissionResponse
forall a. a -> ResourceT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return