    {-# LANGUAGE CPP #-}
    module Aws.S3.Commands.GetService
    where

    import           Aws.Core
    import           Aws.S3.Core
    import           Data.Maybe
    import           Data.Time.Format
    #if !MIN_VERSION_time(1,5,0)
    import           System.Locale
    #endif
    import           Text.XML.Cursor  (($/), ($//), (&|))
    import qualified Data.Text        as T
    import qualified Text.XML.Cursor  as Cu

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

    data GetServiceResponse
        = GetServiceResponse {
            GetServiceResponse -> UserInfo
    gsrOwner :: UserInfo
          , GetServiceResponse -> [BucketInfo]
    gsrBuckets :: [BucketInfo]
          }
        deriving (Int -> GetServiceResponse -> ShowS
    [GetServiceResponse] -> ShowS
    GetServiceResponse -> String
    (Int -> GetServiceResponse -> ShowS)
    -> (GetServiceResponse -> String)
    -> ([GetServiceResponse] -> ShowS)
    -> Show GetServiceResponse
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> GetServiceResponse -> ShowS
    showsPrec :: Int -> GetServiceResponse -> ShowS
    $cshow :: GetServiceResponse -> String
    show :: GetServiceResponse -> String
    $cshowList :: [GetServiceResponse] -> ShowS
    showList :: [GetServiceResponse] -> ShowS
    Show)

    instance ResponseConsumer r GetServiceResponse where
        type ResponseMetadata GetServiceResponse = S3Metadata

        responseConsumer :: Request
    -> r
    -> IORef (ResponseMetadata GetServiceResponse)
    -> HTTPResponseConsumer GetServiceResponse
    responseConsumer Request
    _ r
    _ = (Cursor -> Response S3Metadata GetServiceResponse)
    -> IORef S3Metadata -> HTTPResponseConsumer GetServiceResponse
    forall a.
    (Cursor -> Response S3Metadata a)
    -> IORef S3Metadata -> HTTPResponseConsumer a
    s3XmlResponseConsumer Cursor -> Response S3Metadata GetServiceResponse
    forall {m :: * -> *}.
    MonadThrow m =>
    Cursor -> m GetServiceResponse
    parse
            where
              parse :: Cursor -> m GetServiceResponse
    parse Cursor
    el = do
                owner <- String -> [m UserInfo] -> m UserInfo
    forall (m :: * -> *) a. MonadThrow m => String -> [m a] -> m a
    forceM String
    "Missing Owner" ([m UserInfo] -> m UserInfo) -> [m UserInfo] -> m UserInfo
    forall a b. (a -> b) -> a -> b
    $ Cursor
    el Cursor -> (Cursor -> [m UserInfo]) -> [m UserInfo]
    forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
    $/ Text -> Axis
    Cu.laxElement Text
    "Owner" Axis -> (Cursor -> m UserInfo) -> Cursor -> [m UserInfo]
    forall node a b.
    (Cursor node -> [a]) -> (a -> b) -> Cursor node -> [b]
    &| Cursor -> m UserInfo
    forall (m :: * -> *). MonadThrow m => Cursor -> m UserInfo
    parseUserInfo
                buckets <- sequence $ el $// Cu.laxElement "Bucket" &| parseBucket
                return GetServiceResponse { gsrOwner = owner, gsrBuckets = buckets }

              parseBucket :: Cursor -> m BucketInfo
    parseBucket Cursor
    el = do
                name <- String -> [Text] -> m Text
    forall (m :: * -> *) a. MonadThrow m => String -> [a] -> m a
    force String
    "Missing owner Name" ([Text] -> m Text) -> [Text] -> m Text
    forall a b. (a -> b) -> a -> b
    $ Cursor
    el Cursor -> (Cursor -> [Text]) -> [Text]
    forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
    $/ Text -> Cursor -> [Text]
    elContent Text
    "Name"
                creationDateString <- force "Missing owner CreationDate" $ el $/ elContent "CreationDate" &| T.unpack
                creationDate <- force "Invalid CreationDate" . maybeToList $ parseTimeM True defaultTimeLocale iso8601UtcDate creationDateString
                return BucketInfo { bucketName = name, bucketCreationDate = creationDate }

    -- | ServiceConfiguration: 'S3Configuration'
    instance SignQuery GetService where
        type ServiceConfiguration GetService = S3Configuration
        signQuery :: forall queryType.
    GetService
    -> ServiceConfiguration GetService queryType
    -> SignatureData
    -> SignedQuery
    signQuery GetService
    GetService = S3Query
    -> S3Configuration queryType -> SignatureData -> SignedQuery
    forall qt.
    S3Query -> S3Configuration qt -> SignatureData -> SignedQuery
    s3SignQuery S3Query {
                                    s3QMethod :: Method
    s3QMethod = Method
    Get
                                  , s3QBucket :: Maybe ByteString
    s3QBucket = Maybe ByteString
    forall a. Maybe a
    Nothing
                                  , s3QObject :: Maybe ByteString
    s3QObject = Maybe ByteString
    forall a. Maybe a
    Nothing
                                  , s3QSubresources :: Query
    s3QSubresources = []
                                  , s3QQuery :: Query
    s3QQuery = []
                                  , s3QContentType :: Maybe ByteString
    s3QContentType = Maybe ByteString
    forall a. Maybe a
    Nothing
                                  , s3QContentMd5 :: Maybe (Digest MD5)
    s3QContentMd5 = Maybe (Digest MD5)
    forall a. Maybe a
    Nothing
                                  , s3QAmzHeaders :: RequestHeaders
    s3QAmzHeaders = []
                                  , s3QOtherHeaders :: RequestHeaders
    s3QOtherHeaders = []
                                  , s3QRequestBody :: Maybe RequestBody
    s3QRequestBody = Maybe RequestBody
    forall a. Maybe a
    Nothing
                                  }

    instance Transaction GetService GetServiceResponse

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