    {-# LANGUAGE CPP #-}
    module Aws.Sqs.Core where

    import           Aws.Core
    import           Aws.S3.Core                    (LocationConstraint, locationUsClassic, locationUsWest, locationUsWest2, locationApSouthEast, locationApSouthEast2, locationApNorthEast, locationEu, locationEuWest2)
    import qualified Blaze.ByteString.Builder       as Blaze
    import qualified Blaze.ByteString.Builder.Char8 as Blaze8
    import qualified Control.Exception              as C
    import           Control.Monad
    import           Control.Monad.IO.Class
    import           Control.Monad.Trans.Resource   (MonadThrow, throwM)
    import qualified Data.ByteString                as B
    import qualified Data.ByteString.Char8          as BC
    import qualified Data.Conduit
    import           Data.Conduit                   ((.|))
    import           Data.IORef
    import           Data.List
    import           Data.Maybe
    import           Data.Monoid
    import qualified Data.Semigroup                 as Sem
    import           Data.Ord
    import qualified Data.Text                      as T
    import qualified Data.Text.Encoding             as T
    import qualified Data.Text.Encoding             as TE
    import           Data.Time
    import           Data.Typeable
    import           Prelude
    import qualified Network.HTTP.Conduit           as HTTP
    import qualified Network.HTTP.Types             as HTTP
    #if !MIN_VERSION_time(1,5,0)
    import           System.Locale
    #endif
    import qualified Text.XML                       as XML
    import           Text.XML.Cursor                (($/))
    import qualified Text.XML.Cursor                as Cu

    type ErrorCode = T.Text

    data SqsError
        = SqsError {
            SqsError -> Status
    sqsStatusCode :: HTTP.Status
          , SqsError -> Text
    sqsErrorCode :: ErrorCode
          , SqsError -> Text
    sqsErrorType :: T.Text
          , SqsError -> Text
    sqsErrorMessage :: T.Text
          , SqsError -> Maybe Text
    sqsErrorDetail :: Maybe T.Text
          , SqsError -> Maybe SqsMetadata
    sqsErrorMetadata :: Maybe SqsMetadata
          }
        | SqsXmlError {
            SqsError -> Text
    sqsXmlErrorMessage :: T.Text
          , SqsError -> Maybe SqsMetadata
    sqsXmlErrorMetadata :: Maybe SqsMetadata
          }
        deriving (Int -> SqsError -> ShowS
    [SqsError] -> ShowS
    SqsError -> String
    (Int -> SqsError -> ShowS)
    -> (SqsError -> String) -> ([SqsError] -> ShowS) -> Show SqsError
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> SqsError -> ShowS
    showsPrec :: Int -> SqsError -> ShowS
    $cshow :: SqsError -> String
    show :: SqsError -> String
    $cshowList :: [SqsError] -> ShowS
    showList :: [SqsError] -> ShowS
    Show, Typeable)

    instance C.Exception SqsError

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

    instance Loggable SqsMetadata where
        toLogText :: SqsMetadata -> Text
    toLogText (SqsMetadata Maybe Text
    id2 Maybe Text
    rid) = Text
    "SQS: request ID=" Text -> Text -> Text
    forall a. Monoid a => a -> a -> a
    `mappend`
                                          Text -> Maybe Text -> Text
    forall a. a -> Maybe a -> a
    fromMaybe Text
    "<none>" Maybe Text
    rid Text -> Text -> Text
    forall a. Monoid a => a -> a -> a
    `mappend`
                                          Text
    ", x-amz-id-2=" Text -> Text -> Text
    forall a. Monoid a => a -> a -> a
    `mappend`
                                          Text -> Maybe Text -> Text
    forall a. a -> Maybe a -> a
    fromMaybe Text
    "<none>" Maybe Text
    id2

    instance Sem.Semigroup SqsMetadata where
        SqsMetadata Maybe Text
    a1 Maybe Text
    r1 <> :: SqsMetadata -> SqsMetadata -> SqsMetadata
    <> SqsMetadata Maybe Text
    a2 Maybe Text
    r2 = Maybe Text -> Maybe Text -> SqsMetadata
    SqsMetadata (Maybe Text
    a1 Maybe Text -> Maybe Text -> Maybe Text
    forall a. Maybe a -> Maybe a -> Maybe a
    forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
    `mplus` Maybe Text
    a2) (Maybe Text
    r1 Maybe Text -> Maybe Text -> Maybe Text
    forall a. Maybe a -> Maybe a -> Maybe a
    forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
    `mplus` Maybe Text
    r2)

    instance Monoid SqsMetadata where
        mempty :: SqsMetadata
    mempty = Maybe Text -> Maybe Text -> SqsMetadata
    SqsMetadata Maybe Text
    forall a. Maybe a
    Nothing Maybe Text
    forall a. Maybe a
    Nothing
        mappend :: SqsMetadata -> SqsMetadata -> SqsMetadata
    mappend = SqsMetadata -> SqsMetadata -> SqsMetadata
    forall a. Semigroup a => a -> a -> a
    (Sem.<>)

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

    data Endpoint
        = Endpoint {
            Endpoint -> ByteString
    endpointHost :: B.ByteString
          , Endpoint -> Text
    endpointDefaultLocationConstraint :: LocationConstraint
          , Endpoint -> [Text]
    endpointAllowedLocationConstraints :: [LocationConstraint]
          }
        deriving (Int -> Endpoint -> ShowS
    [Endpoint] -> ShowS
    Endpoint -> String
    (Int -> Endpoint -> ShowS)
    -> (Endpoint -> String) -> ([Endpoint] -> ShowS) -> Show Endpoint
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Endpoint -> ShowS
    showsPrec :: Int -> Endpoint -> ShowS
    $cshow :: Endpoint -> String
    show :: Endpoint -> String
    $cshowList :: [Endpoint] -> ShowS
    showList :: [Endpoint] -> ShowS
    Show)

    data SqsConfiguration qt
        = SqsConfiguration {
            forall qt. SqsConfiguration qt -> Protocol
    sqsProtocol :: Protocol
          , forall qt. SqsConfiguration qt -> Endpoint
    sqsEndpoint :: Endpoint
          , forall qt. SqsConfiguration qt -> Int
    sqsPort :: Int
          , forall qt. SqsConfiguration qt -> Bool
    sqsUseUri :: Bool
          , forall qt. SqsConfiguration qt -> NominalDiffTime
    sqsDefaultExpiry :: NominalDiffTime
          }
        deriving (Int -> SqsConfiguration qt -> ShowS
    [SqsConfiguration qt] -> ShowS
    SqsConfiguration qt -> String
    (Int -> SqsConfiguration qt -> ShowS)
    -> (SqsConfiguration qt -> String)
    -> ([SqsConfiguration qt] -> ShowS)
    -> Show (SqsConfiguration qt)
    forall qt. Int -> SqsConfiguration qt -> ShowS
    forall qt. [SqsConfiguration qt] -> ShowS
    forall qt. SqsConfiguration qt -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: forall qt. Int -> SqsConfiguration qt -> ShowS
    showsPrec :: Int -> SqsConfiguration qt -> ShowS
    $cshow :: forall qt. SqsConfiguration qt -> String
    show :: SqsConfiguration qt -> String
    $cshowList :: forall qt. [SqsConfiguration qt] -> ShowS
    showList :: [SqsConfiguration qt] -> ShowS
    Show)

    instance DefaultServiceConfiguration (SqsConfiguration NormalQuery) where
        defServiceConfig :: SqsConfiguration NormalQuery
    defServiceConfig = Protocol -> Endpoint -> Bool -> SqsConfiguration NormalQuery
    forall qt. Protocol -> Endpoint -> Bool -> SqsConfiguration qt
    sqs Protocol
    HTTPS Endpoint
    sqsEndpointUsClassic Bool
    False
        debugServiceConfig :: SqsConfiguration NormalQuery
    debugServiceConfig = Protocol -> Endpoint -> Bool -> SqsConfiguration NormalQuery
    forall qt. Protocol -> Endpoint -> Bool -> SqsConfiguration qt
    sqs Protocol
    HTTP Endpoint
    sqsEndpointUsClassic Bool
    False

    instance DefaultServiceConfiguration (SqsConfiguration UriOnlyQuery) where
        defServiceConfig :: SqsConfiguration UriOnlyQuery
    defServiceConfig = Protocol -> Endpoint -> Bool -> SqsConfiguration UriOnlyQuery
    forall qt. Protocol -> Endpoint -> Bool -> SqsConfiguration qt
    sqs Protocol
    HTTPS Endpoint
    sqsEndpointUsClassic Bool
    True
        debugServiceConfig :: SqsConfiguration UriOnlyQuery
    debugServiceConfig = Protocol -> Endpoint -> Bool -> SqsConfiguration UriOnlyQuery
    forall qt. Protocol -> Endpoint -> Bool -> SqsConfiguration qt
    sqs Protocol
    HTTP Endpoint
    sqsEndpointUsClassic Bool
    True

    sqsEndpointUsClassic :: Endpoint
    sqsEndpointUsClassic :: Endpoint
    sqsEndpointUsClassic
        = Endpoint {
            endpointHost :: ByteString
    endpointHost = ByteString
    "queue.amazonaws.com"
          , endpointDefaultLocationConstraint :: Text
    endpointDefaultLocationConstraint = Text
    locationUsClassic
          , endpointAllowedLocationConstraints :: [Text]
    endpointAllowedLocationConstraints = [Text
    locationUsClassic
                                                 , Text
    locationUsWest
                                                 , Text
    locationEu
                                                 , Text
    locationApSouthEast
                                                 , Text
    locationApNorthEast]
          }

    sqsEndpointUsWest :: Endpoint
    sqsEndpointUsWest :: Endpoint
    sqsEndpointUsWest
        = Endpoint {
            endpointHost :: ByteString
    endpointHost = ByteString
    "us-west-1.queue.amazonaws.com"
          , endpointDefaultLocationConstraint :: Text
    endpointDefaultLocationConstraint = Text
    locationUsWest
          , endpointAllowedLocationConstraints :: [Text]
    endpointAllowedLocationConstraints = [Text
    locationUsWest]
          }

    sqsEndpointUsWest2 :: Endpoint
    sqsEndpointUsWest2 :: Endpoint
    sqsEndpointUsWest2
        = Endpoint {
            endpointHost :: ByteString
    endpointHost = ByteString
    "us-west-2.queue.amazonaws.com"
          , endpointDefaultLocationConstraint :: Text
    endpointDefaultLocationConstraint = Text
    locationUsWest2
          , endpointAllowedLocationConstraints :: [Text]
    endpointAllowedLocationConstraints = [Text
    locationUsWest2]
          }

    sqsEndpointEu :: Endpoint
    sqsEndpointEu :: Endpoint
    sqsEndpointEu
        = Endpoint {
            endpointHost :: ByteString
    endpointHost = ByteString
    "eu-west-1.queue.amazonaws.com"
          , endpointDefaultLocationConstraint :: Text
    endpointDefaultLocationConstraint = Text
    locationEu
          , endpointAllowedLocationConstraints :: [Text]
    endpointAllowedLocationConstraints = [Text
    locationEu]
          }

    sqsEndpointEuWest2 :: Endpoint
    sqsEndpointEuWest2 :: Endpoint
    sqsEndpointEuWest2
        = Endpoint {
            endpointHost :: ByteString
    endpointHost = ByteString
    "eu-west-2.queue.amazonaws.com"
          , endpointDefaultLocationConstraint :: Text
    endpointDefaultLocationConstraint = Text
    locationEuWest2
          , endpointAllowedLocationConstraints :: [Text]
    endpointAllowedLocationConstraints = [Text
    locationEuWest2]
          }

    sqsEndpointApSouthEast :: Endpoint
    sqsEndpointApSouthEast :: Endpoint
    sqsEndpointApSouthEast
        = Endpoint {
            endpointHost :: ByteString
    endpointHost = ByteString
    "ap-southeast-1.queue.amazonaws.com"
          , endpointDefaultLocationConstraint :: Text
    endpointDefaultLocationConstraint = Text
    locationApSouthEast
          , endpointAllowedLocationConstraints :: [Text]
    endpointAllowedLocationConstraints = [Text
    locationApSouthEast]
          }

    sqsEndpointApSouthEast2 :: Endpoint
    sqsEndpointApSouthEast2 :: Endpoint
    sqsEndpointApSouthEast2
        = Endpoint {
            endpointHost :: ByteString
    endpointHost = ByteString
    "sqs.ap-southeast-2.amazonaws.com"
          , endpointDefaultLocationConstraint :: Text
    endpointDefaultLocationConstraint = Text
    locationApSouthEast2
          , endpointAllowedLocationConstraints :: [Text]
    endpointAllowedLocationConstraints = [Text
    locationApSouthEast2]
          }

    sqsEndpointApNorthEast :: Endpoint
    sqsEndpointApNorthEast :: Endpoint
    sqsEndpointApNorthEast
        = Endpoint {
            endpointHost :: ByteString
    endpointHost = ByteString
    "sqs.ap-northeast-1.amazonaws.com"
          , endpointDefaultLocationConstraint :: Text
    endpointDefaultLocationConstraint = Text
    locationApNorthEast
          , endpointAllowedLocationConstraints :: [Text]
    endpointAllowedLocationConstraints = [Text
    locationApNorthEast]
          }

    sqs :: Protocol -> Endpoint -> Bool -> SqsConfiguration qt
    sqs :: forall qt. Protocol -> Endpoint -> Bool -> SqsConfiguration qt
    sqs Protocol
    protocol Endpoint
    endpoint Bool
    uri
        = SqsConfiguration {
            sqsProtocol :: Protocol
    sqsProtocol = Protocol
    protocol
          , sqsEndpoint :: Endpoint
    sqsEndpoint = Endpoint
    endpoint
          , sqsPort :: Int
    sqsPort = Protocol -> Int
    defaultPort Protocol
    protocol
          , sqsUseUri :: Bool
    sqsUseUri = Bool
    uri
          , sqsDefaultExpiry :: NominalDiffTime
    sqsDefaultExpiry = NominalDiffTime
    15NominalDiffTime -> NominalDiffTime -> NominalDiffTime
    forall a. Num a => a -> a -> a
    *NominalDiffTime
    60
          }

    data SqsQuery = SqsQuery{
      SqsQuery -> Maybe QueueName
    sqsQueueName :: Maybe QueueName,
      SqsQuery -> Query
    sqsQuery :: HTTP.Query
    }

    sqsSignQuery :: SqsQuery -> SqsConfiguration qt -> SignatureData -> SignedQuery
    sqsSignQuery :: forall qt.
    SqsQuery -> SqsConfiguration qt -> SignatureData -> SignedQuery
    sqsSignQuery SqsQuery{Query
    Maybe QueueName
    sqsQueueName :: SqsQuery -> Maybe QueueName
    sqsQuery :: SqsQuery -> Query
    sqsQueueName :: Maybe QueueName
    sqsQuery :: Query
    ..} SqsConfiguration{Bool
    Int
    NominalDiffTime
    Protocol
    Endpoint
    sqsProtocol :: forall qt. SqsConfiguration qt -> Protocol
    sqsEndpoint :: forall qt. SqsConfiguration qt -> Endpoint
    sqsPort :: forall qt. SqsConfiguration qt -> Int
    sqsUseUri :: forall qt. SqsConfiguration qt -> Bool
    sqsDefaultExpiry :: forall qt. SqsConfiguration qt -> NominalDiffTime
    sqsProtocol :: Protocol
    sqsEndpoint :: Endpoint
    sqsPort :: Int
    sqsUseUri :: Bool
    sqsDefaultExpiry :: NominalDiffTime
    ..} SignatureData{UTCTime
    AbsoluteTimeInfo
    Credentials
    signatureTimeInfo :: AbsoluteTimeInfo
    signatureTime :: UTCTime
    signatureCredentials :: Credentials
    signatureCredentials :: SignatureData -> Credentials
    signatureTime :: SignatureData -> UTCTime
    signatureTimeInfo :: SignatureData -> AbsoluteTimeInfo
    ..}
        = SignedQuery {
            sqMethod :: Method
    sqMethod = Method
    method
          , sqProtocol :: Protocol
    sqProtocol = Protocol
    sqsProtocol
          , sqHost :: ByteString
    sqHost = Endpoint -> ByteString
    endpointHost Endpoint
    sqsEndpoint
          , sqPort :: Int
    sqPort = Int
    sqsPort
          , sqPath :: ByteString
    sqPath = ByteString
    path
          , sqQuery :: Query
    sqQuery = Query
    signedQuery
          , sqDate :: Maybe UTCTime
    sqDate = UTCTime -> Maybe UTCTime
    forall a. a -> Maybe a
    Just UTCTime
    signatureTime
          , sqAuthorization :: Maybe (IO ByteString)
    sqAuthorization = Maybe (IO ByteString)
    forall a. Maybe a
    Nothing
          , sqBody :: Maybe RequestBody
    sqBody = Maybe RequestBody
    forall a. Maybe a
    Nothing
          , sqStringToSign :: ByteString
    sqStringToSign = ByteString
    stringToSign
          , sqContentType :: Maybe ByteString
    sqContentType = Maybe ByteString
    forall a. Maybe a
    Nothing
          , sqContentMd5 :: Maybe (Digest MD5)
    sqContentMd5 = Maybe (Digest MD5)
    forall a. Maybe a
    Nothing
          , sqAmzHeaders :: RequestHeaders
    sqAmzHeaders = []
          , sqOtherHeaders :: RequestHeaders
    sqOtherHeaders = []
          }
        where
          method :: Method
    method = Method
    PostQuery
          path :: ByteString
    path = case Maybe QueueName
    sqsQueueName of
                    Just QueueName
    x -> Text -> ByteString
    TE.encodeUtf8 (Text -> ByteString) -> Text -> ByteString
    forall a b. (a -> b) -> a -> b
    $ QueueName -> Text
    printQueueName QueueName
    x
                    Maybe QueueName
    Nothing -> ByteString
    "/"
          expandedQuery :: Query
    expandedQuery = ((ByteString, Maybe ByteString)
     -> (ByteString, Maybe ByteString) -> Ordering)
    -> Query -> Query
    forall a. (a -> a -> Ordering) -> [a] -> [a]
    sortBy (((ByteString, Maybe ByteString) -> ByteString)
    -> (ByteString, Maybe ByteString)
    -> (ByteString, Maybe ByteString)
    -> Ordering
    forall a b. Ord a => (b -> a) -> b -> b -> Ordering
    comparing (ByteString, Maybe ByteString) -> ByteString
    forall a b. (a, b) -> a
    fst)
                           ( Query
    sqsQuery Query -> Query -> Query
    forall a. [a] -> [a] -> [a]
    ++ [ (ByteString
    "AWSAccessKeyId", ByteString -> Maybe ByteString
    forall a. a -> Maybe a
    Just(Credentials -> ByteString
    accessKeyID Credentials
    signatureCredentials)),
                           (ByteString
    "Expires", ByteString -> Maybe ByteString
    forall a. a -> Maybe a
    Just(String -> ByteString
    BC.pack String
    expiresString)),
                           (ByteString
    "SignatureMethod", ByteString -> Maybe ByteString
    forall a. a -> Maybe a
    Just(ByteString
    "HmacSHA256")), (ByteString
    "SignatureVersion",ByteString -> Maybe ByteString
    forall a. a -> Maybe a
    Just(ByteString
    "2")), (ByteString
    "Version",ByteString -> Maybe ByteString
    forall a. a -> Maybe a
    Just(ByteString
    "2012-11-05"))] Query -> Query -> Query
    forall a. [a] -> [a] -> [a]
    ++
                           Query -> (ByteString -> Query) -> Maybe ByteString -> Query
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [] (\ByteString
    tok -> [(ByteString
    "SecurityToken", ByteString -> Maybe ByteString
    forall a. a -> Maybe a
    Just ByteString
    tok)]) (Credentials -> Maybe ByteString
    iamToken Credentials
    signatureCredentials))

          expires :: AbsoluteTimeInfo
    expires = UTCTime -> AbsoluteTimeInfo
    AbsoluteExpires (UTCTime -> AbsoluteTimeInfo) -> UTCTime -> AbsoluteTimeInfo
    forall a b. (a -> b) -> a -> b
    $ NominalDiffTime
    sqsDefaultExpiry NominalDiffTime -> UTCTime -> UTCTime
    `addUTCTime` UTCTime
    signatureTime

          expiresString :: String
    expiresString = TimeLocale -> String -> UTCTime -> String
    forall t. FormatTime t => TimeLocale -> String -> t -> String
    formatTime TimeLocale
    defaultTimeLocale String
    "%FT%TZ" (AbsoluteTimeInfo -> UTCTime
    fromAbsoluteTimeInfo AbsoluteTimeInfo
    expires)

          sig :: ByteString
    sig = Credentials -> AuthorizationHash -> ByteString -> ByteString
    signature Credentials
    signatureCredentials AuthorizationHash
    HmacSHA256 ByteString
    stringToSign
          stringToSign :: ByteString
    stringToSign = Builder -> ByteString
    Blaze.toByteString (Builder -> ByteString)
    -> ([[Builder]] -> Builder) -> [[Builder]] -> ByteString
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Builder] -> Builder
    forall a. Monoid a => [a] -> a
    mconcat ([Builder] -> Builder)
    -> ([[Builder]] -> [Builder]) -> [[Builder]] -> Builder
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Builder -> [Builder] -> [Builder]
    forall a. a -> [a] -> [a]
    intersperse (Char -> Builder
    Blaze8.fromChar Char
    '\n') ([Builder] -> [Builder])
    -> ([[Builder]] -> [Builder]) -> [[Builder]] -> [Builder]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [[Builder]] -> [Builder]
    forall (t :: * -> *) a. Foldable t => t [a] -> [a]
    concat  ([[Builder]] -> ByteString) -> [[Builder]] -> ByteString
    forall a b. (a -> b) -> a -> b
    $
                           [[ByteString -> Builder
    Blaze.copyByteString (ByteString -> Builder) -> ByteString -> Builder
    forall a b. (a -> b) -> a -> b
    $ Method -> ByteString
    httpMethod Method
    method]
                           , [ByteString -> Builder
    Blaze.copyByteString (ByteString -> Builder) -> ByteString -> Builder
    forall a b. (a -> b) -> a -> b
    $ Endpoint -> ByteString
    endpointHost Endpoint
    sqsEndpoint]
                           , [ByteString -> Builder
    Blaze.copyByteString ByteString
    path]
                           , [ByteString -> Builder
    Blaze.copyByteString (ByteString -> Builder) -> ByteString -> Builder
    forall a b. (a -> b) -> a -> b
    $ Bool -> Query -> ByteString
    HTTP.renderQuery Bool
    False Query
    expandedQuery ]]

          signedQuery :: Query
    signedQuery = Query
    expandedQuery Query -> Query -> Query
    forall a. [a] -> [a] -> [a]
    ++ (SimpleQuery -> Query
    HTTP.simpleQueryToQuery (SimpleQuery -> Query) -> SimpleQuery -> Query
    forall a b. (a -> b) -> a -> b
    $ SimpleQuery
    makeAuthQuery)

          makeAuthQuery :: SimpleQuery
    makeAuthQuery = [(ByteString
    "Signature", ByteString
    sig)]

    sqsResponseConsumer :: HTTPResponseConsumer a
                        -> IORef SqsMetadata
                        -> HTTPResponseConsumer a
    sqsResponseConsumer :: forall a.
    HTTPResponseConsumer a
    -> IORef SqsMetadata -> HTTPResponseConsumer a
    sqsResponseConsumer HTTPResponseConsumer a
    inner IORef SqsMetadata
    metadata Response (ConduitM () ByteString (ResourceT IO) ())
    resp = do
          let headerString :: HeaderName -> Maybe Text
    headerString = (ByteString -> Text) -> Maybe ByteString -> Maybe Text
    forall a b. (a -> b) -> Maybe a -> Maybe b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap ByteString -> Text
    T.decodeUtf8 (Maybe ByteString -> Maybe Text)
    -> (HeaderName -> Maybe ByteString) -> HeaderName -> Maybe Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (HeaderName -> RequestHeaders -> Maybe ByteString)
    -> RequestHeaders -> HeaderName -> Maybe ByteString
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip HeaderName -> RequestHeaders -> Maybe ByteString
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup (Response (ConduitM () ByteString (ResourceT IO) ())
    -> RequestHeaders
    forall body. Response body -> RequestHeaders
    HTTP.responseHeaders Response (ConduitM () ByteString (ResourceT IO) ())
    resp)
          let amzId2 :: Maybe Text
    amzId2 = HeaderName -> Maybe Text
    headerString HeaderName
    "x-amz-id-2"
          let requestId :: Maybe Text
    requestId = HeaderName -> Maybe Text
    headerString HeaderName
    "x-amz-request-id"

          let m :: SqsMetadata
    m = SqsMetadata { sqsMAmzId2 :: Maybe Text
    sqsMAmzId2 = Maybe Text
    amzId2, sqsMRequestId :: Maybe Text
    sqsMRequestId = Maybe Text
    requestId }
          IO () -> ResourceT IO ()
    forall a. IO a -> ResourceT IO a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO () -> ResourceT IO ()) -> IO () -> ResourceT IO ()
    forall a b. (a -> b) -> a -> b
    $ IORef SqsMetadata -> SqsMetadata -> IO ()
    forall m. Monoid m => IORef m -> m -> IO ()
    tellMetadataRef IORef SqsMetadata
    metadata SqsMetadata
    m

          if Response (ConduitM () ByteString (ResourceT IO) ()) -> Status
    forall body. Response body -> Status
    HTTP.responseStatus Response (ConduitM () ByteString (ResourceT IO) ())
    resp Status -> Status -> Bool
    forall a. Ord a => a -> a -> Bool
    >= Status
    HTTP.status400
            then HTTPResponseConsumer a
    forall a. HTTPResponseConsumer a
    sqsErrorResponseConsumer Response (ConduitM () ByteString (ResourceT IO) ())
    resp
            else HTTPResponseConsumer a
    inner Response (ConduitM () ByteString (ResourceT IO) ())
    resp

    sqsXmlResponseConsumer :: (Cu.Cursor -> Response SqsMetadata a)
                           -> IORef SqsMetadata
                           -> HTTPResponseConsumer a
    sqsXmlResponseConsumer :: forall a.
    (Cursor -> Response SqsMetadata a)
    -> IORef SqsMetadata -> HTTPResponseConsumer a
    sqsXmlResponseConsumer Cursor -> Response SqsMetadata a
    parse IORef SqsMetadata
    metadataRef = HTTPResponseConsumer a
    -> IORef SqsMetadata -> HTTPResponseConsumer a
    forall a.
    HTTPResponseConsumer a
    -> IORef SqsMetadata -> HTTPResponseConsumer a
    sqsResponseConsumer ((Cursor -> Response SqsMetadata a)
    -> IORef SqsMetadata -> HTTPResponseConsumer a
    forall m a.
    Monoid m =>
    (Cursor -> Response m a) -> IORef m -> HTTPResponseConsumer a
    xmlCursorConsumer Cursor -> Response SqsMetadata a
    parse IORef SqsMetadata
    metadataRef) IORef SqsMetadata
    metadataRef

    sqsErrorResponseConsumer :: HTTPResponseConsumer a
    sqsErrorResponseConsumer :: forall a. HTTPResponseConsumer a
    sqsErrorResponseConsumer Response (ConduitM () ByteString (ResourceT IO) ())
    resp
        = do doc <- ConduitT () Void (ResourceT IO) Document -> ResourceT IO Document
    forall (m :: * -> *) r. Monad m => ConduitT () Void m r -> m r
    Data.Conduit.runConduit (ConduitT () Void (ResourceT IO) Document -> ResourceT IO Document)
    -> ConduitT () Void (ResourceT IO) Document
    -> ResourceT IO Document
    forall a b. (a -> b) -> a -> b
    $ Response (ConduitM () ByteString (ResourceT IO) ())
    -> ConduitM () ByteString (ResourceT IO) ()
    forall body. Response body -> body
    HTTP.responseBody Response (ConduitM () ByteString (ResourceT IO) ())
    resp ConduitM () ByteString (ResourceT IO) ()
    -> ConduitT ByteString Void (ResourceT IO) Document
    -> ConduitT () Void (ResourceT IO) Document
    forall (m :: * -> *) a b c r.
    Monad m =>
    ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
    .| ParseSettings -> ConduitT ByteString Void (ResourceT IO) Document
    forall (m :: * -> *) o.
    MonadThrow m =>
    ParseSettings -> ConduitT ByteString o m Document
    XML.sinkDoc ParseSettings
    forall a. Default a => a
    XML.def
             let cursor = Document -> Cursor
    Cu.fromDocument Document
    doc
             liftIO $ case parseError cursor of
               Right SqsError
    err     -> SqsError -> IO a
    forall e a. (HasCallStack, Exception e) => e -> IO a
    forall (m :: * -> *) e a.
    (MonadThrow m, HasCallStack, Exception e) =>
    e -> m a
    throwM SqsError
    err
               Left SomeException
    otherErr -> SomeException -> IO a
    forall e a. (HasCallStack, Exception e) => e -> IO a
    forall (m :: * -> *) e a.
    (MonadThrow m, HasCallStack, Exception e) =>
    e -> m a
    throwM SomeException
    otherErr
        where
          parseError :: Cu.Cursor -> Either C.SomeException SqsError
          parseError :: Cursor -> Either SomeException SqsError
    parseError Cursor
    root = do cursor <- String -> [Cursor] -> Either SomeException Cursor
    forall (m :: * -> *) a. MonadThrow m => String -> [a] -> m a
    force String
    "Missing Error" ([Cursor] -> Either SomeException Cursor)
    -> [Cursor] -> Either SomeException Cursor
    forall a b. (a -> b) -> a -> b
    $ Cursor
    root Cursor -> (Cursor -> [Cursor]) -> [Cursor]
    forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
    $/ Text -> Cursor -> [Cursor]
    Cu.laxElement Text
    "Error"
                               code <- force "Missing error Code" $ cursor $/ elContent "Code"
                               message <- force "Missing error Message" $ cursor $/ elContent "Message"
                               errorType <- force "Missing error Type" $ cursor $/ elContent "Type"
                               let detail = [Text] -> Maybe Text
    forall a. [a] -> Maybe a
    listToMaybe ([Text] -> Maybe Text) -> [Text] -> Maybe Text
    forall a b. (a -> b) -> a -> b
    $ Cursor
    cursor Cursor -> (Cursor -> [Text]) -> [Text]
    forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
    $/ Text -> Cursor -> [Text]
    elContent Text
    "Detail"

                               return SqsError {
                                            sqsStatusCode = HTTP.responseStatus resp
                                          , sqsErrorCode = code
                                          , sqsErrorMessage = message
                                          , sqsErrorType = errorType
                                          , sqsErrorDetail = detail
                                          , sqsErrorMetadata = Nothing
                                          }

    data QueueName = QueueName{
      QueueName -> Text
    qName :: T.Text,
      QueueName -> Text
    qAccountNumber :: T.Text
    } deriving(Int -> QueueName -> ShowS
    [QueueName] -> ShowS
    QueueName -> String
    (Int -> QueueName -> ShowS)
    -> (QueueName -> String)
    -> ([QueueName] -> ShowS)
    -> Show QueueName
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> QueueName -> ShowS
    showsPrec :: Int -> QueueName -> ShowS
    $cshow :: QueueName -> String
    show :: QueueName -> String
    $cshowList :: [QueueName] -> ShowS
    showList :: [QueueName] -> ShowS
    Show, ReadPrec [QueueName]
    ReadPrec QueueName
    Int -> ReadS QueueName
    ReadS [QueueName]
    (Int -> ReadS QueueName)
    -> ReadS [QueueName]
    -> ReadPrec QueueName
    -> ReadPrec [QueueName]
    -> Read QueueName
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS QueueName
    readsPrec :: Int -> ReadS QueueName
    $creadList :: ReadS [QueueName]
    readList :: ReadS [QueueName]
    $creadPrec :: ReadPrec QueueName
    readPrec :: ReadPrec QueueName
    $creadListPrec :: ReadPrec [QueueName]
    readListPrec :: ReadPrec [QueueName]
    Read, QueueName -> QueueName -> Bool
    (QueueName -> QueueName -> Bool)
    -> (QueueName -> QueueName -> Bool) -> Eq QueueName
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: QueueName -> QueueName -> Bool
    == :: QueueName -> QueueName -> Bool
    $c/= :: QueueName -> QueueName -> Bool
    /= :: QueueName -> QueueName -> Bool
    Eq, Eq QueueName
    Eq QueueName =>
    (QueueName -> QueueName -> Ordering)
    -> (QueueName -> QueueName -> Bool)
    -> (QueueName -> QueueName -> Bool)
    -> (QueueName -> QueueName -> Bool)
    -> (QueueName -> QueueName -> Bool)
    -> (QueueName -> QueueName -> QueueName)
    -> (QueueName -> QueueName -> QueueName)
    -> Ord QueueName
    QueueName -> QueueName -> Bool
    QueueName -> QueueName -> Ordering
    QueueName -> QueueName -> QueueName
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: QueueName -> QueueName -> Ordering
    compare :: QueueName -> QueueName -> Ordering
    $c< :: QueueName -> QueueName -> Bool
    < :: QueueName -> QueueName -> Bool
    $c<= :: QueueName -> QueueName -> Bool
    <= :: QueueName -> QueueName -> Bool
    $c> :: QueueName -> QueueName -> Bool
    > :: QueueName -> QueueName -> Bool
    $c>= :: QueueName -> QueueName -> Bool
    >= :: QueueName -> QueueName -> Bool
    $cmax :: QueueName -> QueueName -> QueueName
    max :: QueueName -> QueueName -> QueueName
    $cmin :: QueueName -> QueueName -> QueueName
    min :: QueueName -> QueueName -> QueueName
    Ord)

    printQueueName :: QueueName -> T.Text
    printQueueName :: QueueName -> Text
    printQueueName QueueName
    queue = [Text] -> Text
    T.concat [Text
    "/", (QueueName -> Text
    qAccountNumber QueueName
    queue), Text
    "/", (QueueName -> Text
    qName QueueName
    queue), Text
    "/"]

    data QueueAttribute
        = QueueAll
        | ApproximateNumberOfMessages
        | ApproximateNumberOfMessagesNotVisible
        | VisibilityTimeout
        | CreatedTimestamp
        | LastModifiedTimestamp
        | Policy
        | MaximumMessageSize
        | MessageRetentionPeriod
        | QueueArn
        deriving(Int -> QueueAttribute -> ShowS
    [QueueAttribute] -> ShowS
    QueueAttribute -> String
    (Int -> QueueAttribute -> ShowS)
    -> (QueueAttribute -> String)
    -> ([QueueAttribute] -> ShowS)
    -> Show QueueAttribute
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> QueueAttribute -> ShowS
    showsPrec :: Int -> QueueAttribute -> ShowS
    $cshow :: QueueAttribute -> String
    show :: QueueAttribute -> String
    $cshowList :: [QueueAttribute] -> ShowS
    showList :: [QueueAttribute] -> ShowS
    Show, Int -> QueueAttribute
    QueueAttribute -> Int
    QueueAttribute -> [QueueAttribute]
    QueueAttribute -> QueueAttribute
    QueueAttribute -> QueueAttribute -> [QueueAttribute]
    QueueAttribute
    -> QueueAttribute -> QueueAttribute -> [QueueAttribute]
    (QueueAttribute -> QueueAttribute)
    -> (QueueAttribute -> QueueAttribute)
    -> (Int -> QueueAttribute)
    -> (QueueAttribute -> Int)
    -> (QueueAttribute -> [QueueAttribute])
    -> (QueueAttribute -> QueueAttribute -> [QueueAttribute])
    -> (QueueAttribute -> QueueAttribute -> [QueueAttribute])
    -> (QueueAttribute
        -> QueueAttribute -> QueueAttribute -> [QueueAttribute])
    -> Enum QueueAttribute
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: QueueAttribute -> QueueAttribute
    succ :: QueueAttribute -> QueueAttribute
    $cpred :: QueueAttribute -> QueueAttribute
    pred :: QueueAttribute -> QueueAttribute
    $ctoEnum :: Int -> QueueAttribute
    toEnum :: Int -> QueueAttribute
    $cfromEnum :: QueueAttribute -> Int
    fromEnum :: QueueAttribute -> Int
    $cenumFrom :: QueueAttribute -> [QueueAttribute]
    enumFrom :: QueueAttribute -> [QueueAttribute]
    $cenumFromThen :: QueueAttribute -> QueueAttribute -> [QueueAttribute]
    enumFromThen :: QueueAttribute -> QueueAttribute -> [QueueAttribute]
    $cenumFromTo :: QueueAttribute -> QueueAttribute -> [QueueAttribute]
    enumFromTo :: QueueAttribute -> QueueAttribute -> [QueueAttribute]
    $cenumFromThenTo :: QueueAttribute
    -> QueueAttribute -> QueueAttribute -> [QueueAttribute]
    enumFromThenTo :: QueueAttribute
    -> QueueAttribute -> QueueAttribute -> [QueueAttribute]
    Enum, QueueAttribute -> QueueAttribute -> Bool
    (QueueAttribute -> QueueAttribute -> Bool)
    -> (QueueAttribute -> QueueAttribute -> Bool) -> Eq QueueAttribute
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: QueueAttribute -> QueueAttribute -> Bool
    == :: QueueAttribute -> QueueAttribute -> Bool
    $c/= :: QueueAttribute -> QueueAttribute -> Bool
    /= :: QueueAttribute -> QueueAttribute -> Bool
    Eq)

    data MessageAttribute
        = MessageAll
        -- ^ all values
        | SenderId
        -- ^ the AWS account number (or the IP address, if anonymous access is
        -- allowed) of the sender
        | SentTimestamp
        -- ^ the time when the message was sent (epoch time in milliseconds)
        | ApproximateReceiveCount
        -- ^ the number of times a message has been received but not deleted
        | ApproximateFirstReceiveTimestamp
        -- ^ the time when the message was first received (epoch time in
        -- milliseconds)
        deriving(Int -> MessageAttribute -> ShowS
    [MessageAttribute] -> ShowS
    MessageAttribute -> String
    (Int -> MessageAttribute -> ShowS)
    -> (MessageAttribute -> String)
    -> ([MessageAttribute] -> ShowS)
    -> Show MessageAttribute
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> MessageAttribute -> ShowS
    showsPrec :: Int -> MessageAttribute -> ShowS
    $cshow :: MessageAttribute -> String
    show :: MessageAttribute -> String
    $cshowList :: [MessageAttribute] -> ShowS
    showList :: [MessageAttribute] -> ShowS
    Show,ReadPrec [MessageAttribute]
    ReadPrec MessageAttribute
    Int -> ReadS MessageAttribute
    ReadS [MessageAttribute]
    (Int -> ReadS MessageAttribute)
    -> ReadS [MessageAttribute]
    -> ReadPrec MessageAttribute
    -> ReadPrec [MessageAttribute]
    -> Read MessageAttribute
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS MessageAttribute
    readsPrec :: Int -> ReadS MessageAttribute
    $creadList :: ReadS [MessageAttribute]
    readList :: ReadS [MessageAttribute]
    $creadPrec :: ReadPrec MessageAttribute
    readPrec :: ReadPrec MessageAttribute
    $creadListPrec :: ReadPrec [MessageAttribute]
    readListPrec :: ReadPrec [MessageAttribute]
    Read,MessageAttribute -> MessageAttribute -> Bool
    (MessageAttribute -> MessageAttribute -> Bool)
    -> (MessageAttribute -> MessageAttribute -> Bool)
    -> Eq MessageAttribute
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: MessageAttribute -> MessageAttribute -> Bool
    == :: MessageAttribute -> MessageAttribute -> Bool
    $c/= :: MessageAttribute -> MessageAttribute -> Bool
    /= :: MessageAttribute -> MessageAttribute -> Bool
    Eq,Eq MessageAttribute
    Eq MessageAttribute =>
    (MessageAttribute -> MessageAttribute -> Ordering)
    -> (MessageAttribute -> MessageAttribute -> Bool)
    -> (MessageAttribute -> MessageAttribute -> Bool)
    -> (MessageAttribute -> MessageAttribute -> Bool)
    -> (MessageAttribute -> MessageAttribute -> Bool)
    -> (MessageAttribute -> MessageAttribute -> MessageAttribute)
    -> (MessageAttribute -> MessageAttribute -> MessageAttribute)
    -> Ord MessageAttribute
    MessageAttribute -> MessageAttribute -> Bool
    MessageAttribute -> MessageAttribute -> Ordering
    MessageAttribute -> MessageAttribute -> MessageAttribute
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: MessageAttribute -> MessageAttribute -> Ordering
    compare :: MessageAttribute -> MessageAttribute -> Ordering
    $c< :: MessageAttribute -> MessageAttribute -> Bool
    < :: MessageAttribute -> MessageAttribute -> Bool
    $c<= :: MessageAttribute -> MessageAttribute -> Bool
    <= :: MessageAttribute -> MessageAttribute -> Bool
    $c> :: MessageAttribute -> MessageAttribute -> Bool
    > :: MessageAttribute -> MessageAttribute -> Bool
    $c>= :: MessageAttribute -> MessageAttribute -> Bool
    >= :: MessageAttribute -> MessageAttribute -> Bool
    $cmax :: MessageAttribute -> MessageAttribute -> MessageAttribute
    max :: MessageAttribute -> MessageAttribute -> MessageAttribute
    $cmin :: MessageAttribute -> MessageAttribute -> MessageAttribute
    min :: MessageAttribute -> MessageAttribute -> MessageAttribute
    Ord,Int -> MessageAttribute
    MessageAttribute -> Int
    MessageAttribute -> [MessageAttribute]
    MessageAttribute -> MessageAttribute
    MessageAttribute -> MessageAttribute -> [MessageAttribute]
    MessageAttribute
    -> MessageAttribute -> MessageAttribute -> [MessageAttribute]
    (MessageAttribute -> MessageAttribute)
    -> (MessageAttribute -> MessageAttribute)
    -> (Int -> MessageAttribute)
    -> (MessageAttribute -> Int)
    -> (MessageAttribute -> [MessageAttribute])
    -> (MessageAttribute -> MessageAttribute -> [MessageAttribute])
    -> (MessageAttribute -> MessageAttribute -> [MessageAttribute])
    -> (MessageAttribute
        -> MessageAttribute -> MessageAttribute -> [MessageAttribute])
    -> Enum MessageAttribute
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: MessageAttribute -> MessageAttribute
    succ :: MessageAttribute -> MessageAttribute
    $cpred :: MessageAttribute -> MessageAttribute
    pred :: MessageAttribute -> MessageAttribute
    $ctoEnum :: Int -> MessageAttribute
    toEnum :: Int -> MessageAttribute
    $cfromEnum :: MessageAttribute -> Int
    fromEnum :: MessageAttribute -> Int
    $cenumFrom :: MessageAttribute -> [MessageAttribute]
    enumFrom :: MessageAttribute -> [MessageAttribute]
    $cenumFromThen :: MessageAttribute -> MessageAttribute -> [MessageAttribute]
    enumFromThen :: MessageAttribute -> MessageAttribute -> [MessageAttribute]
    $cenumFromTo :: MessageAttribute -> MessageAttribute -> [MessageAttribute]
    enumFromTo :: MessageAttribute -> MessageAttribute -> [MessageAttribute]
    $cenumFromThenTo :: MessageAttribute
    -> MessageAttribute -> MessageAttribute -> [MessageAttribute]
    enumFromThenTo :: MessageAttribute
    -> MessageAttribute -> MessageAttribute -> [MessageAttribute]
    Enum,MessageAttribute
    MessageAttribute -> MessageAttribute -> Bounded MessageAttribute
    forall a. a -> a -> Bounded a
    $cminBound :: MessageAttribute
    minBound :: MessageAttribute
    $cmaxBound :: MessageAttribute
    maxBound :: MessageAttribute
    Bounded)

    data SqsPermission
        = PermissionAll
        | PermissionSendMessage
        | PermissionReceiveMessage
        | PermissionDeleteMessage
        | PermissionChangeMessageVisibility
        | PermissionGetQueueAttributes
        deriving (Int -> SqsPermission -> ShowS
    [SqsPermission] -> ShowS
    SqsPermission -> String
    (Int -> SqsPermission -> ShowS)
    -> (SqsPermission -> String)
    -> ([SqsPermission] -> ShowS)
    -> Show SqsPermission
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> SqsPermission -> ShowS
    showsPrec :: Int -> SqsPermission -> ShowS
    $cshow :: SqsPermission -> String
    show :: SqsPermission -> String
    $cshowList :: [SqsPermission] -> ShowS
    showList :: [SqsPermission] -> ShowS
    Show, Int -> SqsPermission
    SqsPermission -> Int
    SqsPermission -> [SqsPermission]
    SqsPermission -> SqsPermission
    SqsPermission -> SqsPermission -> [SqsPermission]
    SqsPermission -> SqsPermission -> SqsPermission -> [SqsPermission]
    (SqsPermission -> SqsPermission)
    -> (SqsPermission -> SqsPermission)
    -> (Int -> SqsPermission)
    -> (SqsPermission -> Int)
    -> (SqsPermission -> [SqsPermission])
    -> (SqsPermission -> SqsPermission -> [SqsPermission])
    -> (SqsPermission -> SqsPermission -> [SqsPermission])
    -> (SqsPermission
        -> SqsPermission -> SqsPermission -> [SqsPermission])
    -> Enum SqsPermission
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: SqsPermission -> SqsPermission
    succ :: SqsPermission -> SqsPermission
    $cpred :: SqsPermission -> SqsPermission
    pred :: SqsPermission -> SqsPermission
    $ctoEnum :: Int -> SqsPermission
    toEnum :: Int -> SqsPermission
    $cfromEnum :: SqsPermission -> Int
    fromEnum :: SqsPermission -> Int
    $cenumFrom :: SqsPermission -> [SqsPermission]
    enumFrom :: SqsPermission -> [SqsPermission]
    $cenumFromThen :: SqsPermission -> SqsPermission -> [SqsPermission]
    enumFromThen :: SqsPermission -> SqsPermission -> [SqsPermission]
    $cenumFromTo :: SqsPermission -> SqsPermission -> [SqsPermission]
    enumFromTo :: SqsPermission -> SqsPermission -> [SqsPermission]
    $cenumFromThenTo :: SqsPermission -> SqsPermission -> SqsPermission -> [SqsPermission]
    enumFromThenTo :: SqsPermission -> SqsPermission -> SqsPermission -> [SqsPermission]
    Enum, SqsPermission -> SqsPermission -> Bool
    (SqsPermission -> SqsPermission -> Bool)
    -> (SqsPermission -> SqsPermission -> Bool) -> Eq SqsPermission
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: SqsPermission -> SqsPermission -> Bool
    == :: SqsPermission -> SqsPermission -> Bool
    $c/= :: SqsPermission -> SqsPermission -> Bool
    /= :: SqsPermission -> SqsPermission -> Bool
    Eq)

    parseQueueAttribute :: MonadThrow m  => T.Text -> m QueueAttribute
    parseQueueAttribute :: forall (m :: * -> *). MonadThrow m => Text -> m QueueAttribute
    parseQueueAttribute Text
    "ApproximateNumberOfMessages" = QueueAttribute -> m QueueAttribute
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return QueueAttribute
    ApproximateNumberOfMessages
    parseQueueAttribute Text
    "ApproximateNumberOfMessagesNotVisible" = QueueAttribute -> m QueueAttribute
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return QueueAttribute
    ApproximateNumberOfMessagesNotVisible
    parseQueueAttribute Text
    "VisibilityTimeout" = QueueAttribute -> m QueueAttribute
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return QueueAttribute
    VisibilityTimeout
    parseQueueAttribute Text
    "CreatedTimestamp" = QueueAttribute -> m QueueAttribute
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return QueueAttribute
    CreatedTimestamp
    parseQueueAttribute Text
    "LastModifiedTimestamp" = QueueAttribute -> m QueueAttribute
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return QueueAttribute
    LastModifiedTimestamp
    parseQueueAttribute Text
    "Policy" = QueueAttribute -> m QueueAttribute
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return QueueAttribute
    Policy
    parseQueueAttribute Text
    "MaximumMessageSize" = QueueAttribute -> m QueueAttribute
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return QueueAttribute
    MaximumMessageSize
    parseQueueAttribute Text
    "MessageRetentionPeriod" = QueueAttribute -> m QueueAttribute
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return QueueAttribute
    MessageRetentionPeriod
    parseQueueAttribute Text
    "QueueArn" = QueueAttribute -> m QueueAttribute
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return QueueAttribute
    QueueArn
    parseQueueAttribute Text
    x = XmlException -> m QueueAttribute
    forall e a. (HasCallStack, Exception e) => e -> m a
    forall (m :: * -> *) e a.
    (MonadThrow m, HasCallStack, Exception e) =>
    e -> m a
    throwM (XmlException -> m QueueAttribute)
    -> XmlException -> m QueueAttribute
    forall a b. (a -> b) -> a -> b
    $ String -> XmlException
    XmlException ( String
    "Invalid Attribute Name. " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ Text -> String
    forall a. Show a => a -> String
    show Text
    x)

    printQueueAttribute :: QueueAttribute -> T.Text
    printQueueAttribute :: QueueAttribute -> Text
    printQueueAttribute QueueAttribute
    QueueAll = Text
    "All"
    printQueueAttribute QueueAttribute
    ApproximateNumberOfMessages = Text
    "ApproximateNumberOfMessages"
    printQueueAttribute QueueAttribute
    ApproximateNumberOfMessagesNotVisible = Text
    "ApproximateNumberOfMessagesNotVisible"
    printQueueAttribute QueueAttribute
    VisibilityTimeout = Text
    "VisibilityTimeout"
    printQueueAttribute QueueAttribute
    CreatedTimestamp = Text
    "CreatedTimestamp"
    printQueueAttribute QueueAttribute
    LastModifiedTimestamp = Text
    "LastModifiedTimestamp"
    printQueueAttribute QueueAttribute
    Policy = Text
    "Policy"
    printQueueAttribute QueueAttribute
    MaximumMessageSize = Text
    "MaximumMessageSize"
    printQueueAttribute QueueAttribute
    MessageRetentionPeriod = Text
    "MessageRetentionPeriod"
    printQueueAttribute QueueAttribute
    QueueArn = Text
    "QueueArn"

    parseMessageAttribute :: MonadThrow m  =>  T.Text -> m MessageAttribute
    parseMessageAttribute :: forall (m :: * -> *). MonadThrow m => Text -> m MessageAttribute
    parseMessageAttribute Text
    "SenderId" = MessageAttribute -> m MessageAttribute
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return MessageAttribute
    SenderId
    parseMessageAttribute Text
    "SentTimestamp" = MessageAttribute -> m MessageAttribute
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return MessageAttribute
    SentTimestamp
    parseMessageAttribute Text
    "ApproximateReceiveCount" = MessageAttribute -> m MessageAttribute
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return MessageAttribute
    ApproximateReceiveCount
    parseMessageAttribute Text
    "ApproximateFirstReceiveTimestamp" = MessageAttribute -> m MessageAttribute
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return MessageAttribute
    ApproximateFirstReceiveTimestamp
    parseMessageAttribute Text
    x = XmlException -> m MessageAttribute
    forall e a. (HasCallStack, Exception e) => e -> m a
    forall (m :: * -> *) e a.
    (MonadThrow m, HasCallStack, Exception e) =>
    e -> m a
    throwM (XmlException -> m MessageAttribute)
    -> XmlException -> m MessageAttribute
    forall a b. (a -> b) -> a -> b
    $ String -> XmlException
    XmlException ( String
    "Invalid Attribute Name. " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ Text -> String
    forall a. Show a => a -> String
    show Text
    x)

    printMessageAttribute :: MessageAttribute -> T.Text
    printMessageAttribute :: MessageAttribute -> Text
    printMessageAttribute MessageAttribute
    MessageAll = Text
    "All"
    printMessageAttribute MessageAttribute
    SenderId = Text
    "SenderId"
    printMessageAttribute MessageAttribute
    SentTimestamp = Text
    "SentTimestamp"
    printMessageAttribute MessageAttribute
    ApproximateReceiveCount = Text
    "ApproximateReceiveCount"
    printMessageAttribute MessageAttribute
    ApproximateFirstReceiveTimestamp = Text
    "ApproximateFirstReceiveTimestamp"

    printPermission :: SqsPermission -> T.Text
    printPermission :: SqsPermission -> Text
    printPermission SqsPermission
    PermissionAll = Text
    "*"
    printPermission SqsPermission
    PermissionSendMessage = Text
    "SendMessage"
    printPermission SqsPermission
    PermissionReceiveMessage = Text
    "ReceiveMessage"
    printPermission SqsPermission
    PermissionDeleteMessage = Text
    "DeleteMessage"
    printPermission SqsPermission
    PermissionChangeMessageVisibility = Text
    "ChangeMessageVisibility"
    printPermission SqsPermission
    PermissionGetQueueAttributes = Text
    "GetQueueAttributes"

    newtype ReceiptHandle = ReceiptHandle T.Text deriving(Int -> ReceiptHandle -> ShowS
    [ReceiptHandle] -> ShowS
    ReceiptHandle -> String
    (Int -> ReceiptHandle -> ShowS)
    -> (ReceiptHandle -> String)
    -> ([ReceiptHandle] -> ShowS)
    -> Show ReceiptHandle
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> ReceiptHandle -> ShowS
    showsPrec :: Int -> ReceiptHandle -> ShowS
    $cshow :: ReceiptHandle -> String
    show :: ReceiptHandle -> String
    $cshowList :: [ReceiptHandle] -> ShowS
    showList :: [ReceiptHandle] -> ShowS
    Show, ReadPrec [ReceiptHandle]
    ReadPrec ReceiptHandle
    Int -> ReadS ReceiptHandle
    ReadS [ReceiptHandle]
    (Int -> ReadS ReceiptHandle)
    -> ReadS [ReceiptHandle]
    -> ReadPrec ReceiptHandle
    -> ReadPrec [ReceiptHandle]
    -> Read ReceiptHandle
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS ReceiptHandle
    readsPrec :: Int -> ReadS ReceiptHandle
    $creadList :: ReadS [ReceiptHandle]
    readList :: ReadS [ReceiptHandle]
    $creadPrec :: ReadPrec ReceiptHandle
    readPrec :: ReadPrec ReceiptHandle
    $creadListPrec :: ReadPrec [ReceiptHandle]
    readListPrec :: ReadPrec [ReceiptHandle]
    Read, ReceiptHandle -> ReceiptHandle -> Bool
    (ReceiptHandle -> ReceiptHandle -> Bool)
    -> (ReceiptHandle -> ReceiptHandle -> Bool) -> Eq ReceiptHandle
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: ReceiptHandle -> ReceiptHandle -> Bool
    == :: ReceiptHandle -> ReceiptHandle -> Bool
    $c/= :: ReceiptHandle -> ReceiptHandle -> Bool
    /= :: ReceiptHandle -> ReceiptHandle -> Bool
    Eq, Eq ReceiptHandle
    Eq ReceiptHandle =>
    (ReceiptHandle -> ReceiptHandle -> Ordering)
    -> (ReceiptHandle -> ReceiptHandle -> Bool)
    -> (ReceiptHandle -> ReceiptHandle -> Bool)
    -> (ReceiptHandle -> ReceiptHandle -> Bool)
    -> (ReceiptHandle -> ReceiptHandle -> Bool)
    -> (ReceiptHandle -> ReceiptHandle -> ReceiptHandle)
    -> (ReceiptHandle -> ReceiptHandle -> ReceiptHandle)
    -> Ord ReceiptHandle
    ReceiptHandle -> ReceiptHandle -> Bool
    ReceiptHandle -> ReceiptHandle -> Ordering
    ReceiptHandle -> ReceiptHandle -> ReceiptHandle
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: ReceiptHandle -> ReceiptHandle -> Ordering
    compare :: ReceiptHandle -> ReceiptHandle -> Ordering
    $c< :: ReceiptHandle -> ReceiptHandle -> Bool
    < :: ReceiptHandle -> ReceiptHandle -> Bool
    $c<= :: ReceiptHandle -> ReceiptHandle -> Bool
    <= :: ReceiptHandle -> ReceiptHandle -> Bool
    $c> :: ReceiptHandle -> ReceiptHandle -> Bool
    > :: ReceiptHandle -> ReceiptHandle -> Bool
    $c>= :: ReceiptHandle -> ReceiptHandle -> Bool
    >= :: ReceiptHandle -> ReceiptHandle -> Bool
    $cmax :: ReceiptHandle -> ReceiptHandle -> ReceiptHandle
    max :: ReceiptHandle -> ReceiptHandle -> ReceiptHandle
    $cmin :: ReceiptHandle -> ReceiptHandle -> ReceiptHandle
    min :: ReceiptHandle -> ReceiptHandle -> ReceiptHandle
    Ord)
    newtype MessageId = MessageId T.Text deriving(Int -> MessageId -> ShowS
    [MessageId] -> ShowS
    MessageId -> String
    (Int -> MessageId -> ShowS)
    -> (MessageId -> String)
    -> ([MessageId] -> ShowS)
    -> Show MessageId
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> MessageId -> ShowS
    showsPrec :: Int -> MessageId -> ShowS
    $cshow :: MessageId -> String
    show :: MessageId -> String
    $cshowList :: [MessageId] -> ShowS
    showList :: [MessageId] -> ShowS
    Show, ReadPrec [MessageId]
    ReadPrec MessageId
    Int -> ReadS MessageId
    ReadS [MessageId]
    (Int -> ReadS MessageId)
    -> ReadS [MessageId]
    -> ReadPrec MessageId
    -> ReadPrec [MessageId]
    -> Read MessageId
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS MessageId
    readsPrec :: Int -> ReadS MessageId
    $creadList :: ReadS [MessageId]
    readList :: ReadS [MessageId]
    $creadPrec :: ReadPrec MessageId
    readPrec :: ReadPrec MessageId
    $creadListPrec :: ReadPrec [MessageId]
    readListPrec :: ReadPrec [MessageId]
    Read, MessageId -> MessageId -> Bool
    (MessageId -> MessageId -> Bool)
    -> (MessageId -> MessageId -> Bool) -> Eq MessageId
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: MessageId -> MessageId -> Bool
    == :: MessageId -> MessageId -> Bool
    $c/= :: MessageId -> MessageId -> Bool
    /= :: MessageId -> MessageId -> Bool
    Eq, Eq MessageId
    Eq MessageId =>
    (MessageId -> MessageId -> Ordering)
    -> (MessageId -> MessageId -> Bool)
    -> (MessageId -> MessageId -> Bool)
    -> (MessageId -> MessageId -> Bool)
    -> (MessageId -> MessageId -> Bool)
    -> (MessageId -> MessageId -> MessageId)
    -> (MessageId -> MessageId -> MessageId)
    -> Ord MessageId
    MessageId -> MessageId -> Bool
    MessageId -> MessageId -> Ordering
    MessageId -> MessageId -> MessageId
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: MessageId -> MessageId -> Ordering
    compare :: MessageId -> MessageId -> Ordering
    $c< :: MessageId -> MessageId -> Bool
    < :: MessageId -> MessageId -> Bool
    $c<= :: MessageId -> MessageId -> Bool
    <= :: MessageId -> MessageId -> Bool
    $c> :: MessageId -> MessageId -> Bool
    > :: MessageId -> MessageId -> Bool
    $c>= :: MessageId -> MessageId -> Bool
    >= :: MessageId -> MessageId -> Bool
    $cmax :: MessageId -> MessageId -> MessageId
    max :: MessageId -> MessageId -> MessageId
    $cmin :: MessageId -> MessageId -> MessageId
    min :: MessageId -> MessageId -> MessageId
    Ord)

    printReceiptHandle :: ReceiptHandle -> T.Text
    printReceiptHandle :: ReceiptHandle -> Text
    printReceiptHandle (ReceiptHandle Text
    handle) = Text
    handle