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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VersioningState] -> ShowS
$cshowList :: [VersioningState] -> ShowS
show :: VersioningState -> String
$cshow :: VersioningState -> String
showsPrec :: Int -> VersioningState -> ShowS
$cshowsPrec :: Int -> 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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutBucketVersioning] -> ShowS
$cshowList :: [PutBucketVersioning] -> ShowS
show :: PutBucketVersioning -> String
$cshow :: PutBucketVersioning -> String
showsPrec :: Int -> PutBucketVersioning -> ShowS
$cshowsPrec :: Int -> 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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutBucketVersioningResponse] -> ShowS
$cshowList :: [PutBucketVersioningResponse] -> ShowS
show :: PutBucketVersioningResponse -> String
$cshow :: PutBucketVersioningResponse -> String
showsPrec :: Int -> PutBucketVersioningResponse -> ShowS
$cshowsPrec :: Int -> 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
pbvVersioningConfiguration :: VersioningState
pbvBucket :: Bucket
pbvVersioningConfiguration :: PutBucketVersioning -> VersioningState
pbvBucket :: PutBucketVersioning -> Bucket
..} = forall qt.
S3Query -> S3Configuration qt -> SignatureData -> SignedQuery
s3SignQuery forall a b. (a -> b) -> a -> b
$ S3Query
      { s3QMethod :: Method
s3QMethod       = Method
Put
      , s3QBucket :: Maybe ByteString
s3QBucket       = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Bucket -> ByteString
T.encodeUtf8 Bucket
pbvBucket
      , s3QSubresources :: Query
s3QSubresources = forall a. QueryLike a => a -> Query
toQuery [(ByteString
"versioning" :: B8.ByteString, forall a. Maybe a
Nothing :: Maybe B8.ByteString)]
      , s3QQuery :: Query
s3QQuery        = []
      , s3QContentType :: Maybe ByteString
s3QContentType  = forall a. Maybe a
Nothing
      , s3QContentMd5 :: Maybe (Digest MD5)
s3QContentMd5   = forall a. Maybe a
Nothing
      , s3QObject :: Maybe ByteString
s3QObject       = forall a. Maybe a
Nothing
      , s3QAmzHeaders :: RequestHeaders
s3QAmzHeaders   = []
      , s3QOtherHeaders :: RequestHeaders
s3QOtherHeaders = []
      , s3QRequestBody :: Maybe RequestBody
s3QRequestBody  = (forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> RequestBody
HTTP.RequestBodyLBS forall b c a. (b -> c) -> (a -> b) -> a -> c
. RenderSettings -> Document -> ByteString
XML.renderLBS forall a. Default a => a
XML.def)
         XML.Document
          { documentPrologue :: Prologue
XML.documentPrologue = [Miscellaneous] -> Maybe Doctype -> [Miscellaneous] -> Prologue
XML.Prologue [] 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 = 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 = 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
_ = forall a.
HTTPResponseConsumer a
-> IORef S3Metadata -> HTTPResponseConsumer a
s3ResponseConsumer forall a b. (a -> b) -> a -> b
$ \Response (ConduitM () ByteString (ResourceT IO) ())
_ -> 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 = forall (m :: * -> *) a. Monad m => a -> m a
return