    module Aws.S3.Commands.PutBucketVersioning where

    import           Aws.Core
    import           Aws.S3.Core
    import           Network.HTTP.Types (toQuery)
    import qualified Data.Map             as M
    import qualified Data.Text.Encoding   as T
    import qualified Network.HTTP.Conduit as HTTP
    import qualified Text.XML             as XML
    import qualified Data.ByteString.Lazy.Char8 as B8

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

    -- | Sets the versioning state of an existing bucket.
    data PutBucketVersioning
        = PutBucketVersioning
          { PutBucketVersioning -> Bucket
    pbvBucket :: Bucket
          , PutBucketVersioning -> VersioningState
    pbvVersioningConfiguration :: VersioningState
          }
        deriving (Int -> PutBucketVersioning -> ShowS
    [PutBucketVersioning] -> ShowS
    PutBucketVersioning -> String
    (Int -> PutBucketVersioning -> ShowS)
    -> (PutBucketVersioning -> String)
    -> ([PutBucketVersioning] -> ShowS)
    -> Show PutBucketVersioning
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> PutBucketVersioning -> ShowS
    showsPrec :: Int -> PutBucketVersioning -> ShowS
    $cshow :: PutBucketVersioning -> String
    show :: PutBucketVersioning -> String
    $cshowList :: [PutBucketVersioning] -> ShowS
    showList :: [PutBucketVersioning] -> ShowS
    Show)

    putBucketVersioning :: Bucket -> VersioningState -> PutBucketVersioning
    putBucketVersioning :: Bucket -> VersioningState -> PutBucketVersioning
    putBucketVersioning = Bucket -> VersioningState -> PutBucketVersioning
    PutBucketVersioning

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

    -- | ServiceConfiguration: 'S3Configuration'
    instance SignQuery PutBucketVersioning where
        type ServiceConfiguration PutBucketVersioning = S3Configuration

        signQuery :: forall queryType.
    PutBucketVersioning
    -> ServiceConfiguration PutBucketVersioning queryType
    -> SignatureData
    -> SignedQuery
    signQuery PutBucketVersioning{Bucket
    VersioningState
    pbvBucket :: PutBucketVersioning -> Bucket
    pbvVersioningConfiguration :: PutBucketVersioning -> VersioningState
    pbvBucket :: Bucket
    pbvVersioningConfiguration :: VersioningState
    ..} = S3Query
    -> S3Configuration queryType -> SignatureData -> SignedQuery
    forall qt.
    S3Query -> S3Configuration qt -> SignatureData -> SignedQuery
    s3SignQuery (S3Query
     -> S3Configuration queryType -> SignatureData -> SignedQuery)
    -> S3Query
    -> S3Configuration queryType
    -> SignatureData
    -> SignedQuery
    forall a b. (a -> b) -> a -> b
    $ S3Query
          { s3QMethod :: Method
    s3QMethod       = Method
    Put
          , s3QBucket :: Maybe ByteString
    s3QBucket       = ByteString -> Maybe ByteString
    forall a. a -> Maybe a
    Just (ByteString -> Maybe ByteString) -> ByteString -> Maybe ByteString
    forall a b. (a -> b) -> a -> b
    $ Bucket -> ByteString
    T.encodeUtf8 Bucket
    pbvBucket
          , s3QSubresources :: Query
    s3QSubresources = [(ByteString, Maybe ByteString)] -> Query
    forall a. QueryLike a => a -> Query
    toQuery [(ByteString
    "versioning" :: B8.ByteString, Maybe ByteString
    forall a. Maybe a
    Nothing :: Maybe B8.ByteString)]
          , 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
          , s3QObject :: Maybe ByteString
    s3QObject       = Maybe ByteString
    forall a. Maybe a
    Nothing
          , s3QAmzHeaders :: RequestHeaders
    s3QAmzHeaders   = []
          , s3QOtherHeaders :: RequestHeaders
    s3QOtherHeaders = []
          , s3QRequestBody :: Maybe RequestBody
    s3QRequestBody  = (RequestBody -> Maybe RequestBody
    forall a. a -> Maybe a
    Just (RequestBody -> Maybe RequestBody)
    -> (Document -> RequestBody) -> Document -> Maybe RequestBody
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ByteString -> RequestBody
    HTTP.RequestBodyLBS (ByteString -> RequestBody)
    -> (Document -> ByteString) -> Document -> RequestBody
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . RenderSettings -> Document -> ByteString
    XML.renderLBS RenderSettings
    forall a. Default a => a
    XML.def)
             XML.Document
              { documentPrologue :: Prologue
    XML.documentPrologue = [Miscellaneous] -> Maybe Doctype -> [Miscellaneous] -> Prologue
    XML.Prologue [] Maybe Doctype
    forall a. Maybe a
    Nothing []
              , documentRoot :: Element
    XML.documentRoot = XML.Element
                { elementName :: Name
    XML.elementName = Name
    "{http://s3.amazonaws.com/doc/2006-03-01/}VersioningConfiguration"
                , elementAttributes :: Map Name Bucket
    XML.elementAttributes = Map Name Bucket
    forall k a. Map k a
    M.empty
                , elementNodes :: [Node]
    XML.elementNodes = [ Element -> Node
    XML.NodeElement (XML.Element
                  { elementName :: Name
    XML.elementName = Name
    "{http://s3.amazonaws.com/doc/2006-03-01/}Status"
                  , elementAttributes :: Map Name Bucket
    XML.elementAttributes = Map Name Bucket
    forall k a. Map k a
    M.empty
                  , elementNodes :: [Node]
    XML.elementNodes = case VersioningState
    pbvVersioningConfiguration of
                    VersioningState
    VersioningSuspended -> [Bucket -> Node
    XML.NodeContent Bucket
    "Suspended"]
                    VersioningState
    VersioningEnabled ->  [Bucket -> Node
    XML.NodeContent Bucket
    "Enabled"]
                  })]
                }
              , documentEpilogue :: [Miscellaneous]
    XML.documentEpilogue = []
              }
          }

    instance ResponseConsumer r PutBucketVersioningResponse where
        type ResponseMetadata PutBucketVersioningResponse = S3Metadata

        responseConsumer :: Request
    -> r
    -> IORef (ResponseMetadata PutBucketVersioningResponse)
    -> HTTPResponseConsumer PutBucketVersioningResponse
    responseConsumer Request
    _ r
    _ = HTTPResponseConsumer PutBucketVersioningResponse
    -> IORef S3Metadata
    -> HTTPResponseConsumer PutBucketVersioningResponse
    forall a.
    HTTPResponseConsumer a
    -> IORef S3Metadata -> HTTPResponseConsumer a
    s3ResponseConsumer (HTTPResponseConsumer PutBucketVersioningResponse
     -> IORef S3Metadata
     -> HTTPResponseConsumer PutBucketVersioningResponse)
    -> HTTPResponseConsumer PutBucketVersioningResponse
    -> IORef S3Metadata
    -> HTTPResponseConsumer PutBucketVersioningResponse
    forall a b. (a -> b) -> a -> b
    $ \Response (ConduitM () ByteString (ResourceT IO) ())
    _ -> PutBucketVersioningResponse
    -> ResourceT IO PutBucketVersioningResponse
    forall a. a -> ResourceT IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return PutBucketVersioningResponse
    PutBucketVersioningResponse

    instance Transaction PutBucketVersioning PutBucketVersioningResponse

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