{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}

-- |
-- Module      : Network.DO.Spaces.Actions.SetBucketACLs
-- Copyright   : (c) 2021 Rory Tyler Hayford
-- License     : BSD-3-Clause
-- Maintainer  : rory.hayford@protonmail.com
-- Stability   : experimental
-- Portability : GHC
--
module Network.DO.Spaces.Actions.SetBucketACLs
    ( SetBucketACLs(..)
    , SetBucketACLsResponse
    ) where

import           Control.Monad.Reader        ( MonadReader(ask) )

import           Data.ByteString             ( ByteString )

import           GHC.Generics                ( Generic )

import           Network.DO.Spaces.Types
                 ( Action(..)
                 , Bucket
                 , Grant(..)
                 , Method(PUT)
                 , MonadSpaces
                 , Owner
                 , SpacesRequestBuilder(..)
                 )
import           Network.DO.Spaces.Utils     ( writeACLSetter )
import           Network.HTTP.Client.Conduit ( RequestBody(RequestBodyLBS) )
import qualified Network.HTTP.Types          as H

data SetBucketACLs = SetBucketACLs
    { SetBucketACLs -> Bucket
bucket :: Bucket
    , SetBucketACLs -> [Grant]
acls   :: [Grant]
    , SetBucketACLs -> Owner
owner  :: Owner -- ^ The bucket owner
    }
    deriving ( Int -> SetBucketACLs -> ShowS
[SetBucketACLs] -> ShowS
SetBucketACLs -> String
(Int -> SetBucketACLs -> ShowS)
-> (SetBucketACLs -> String)
-> ([SetBucketACLs] -> ShowS)
-> Show SetBucketACLs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SetBucketACLs] -> ShowS
$cshowList :: [SetBucketACLs] -> ShowS
show :: SetBucketACLs -> String
$cshow :: SetBucketACLs -> String
showsPrec :: Int -> SetBucketACLs -> ShowS
$cshowsPrec :: Int -> SetBucketACLs -> ShowS
Show, SetBucketACLs -> SetBucketACLs -> Bool
(SetBucketACLs -> SetBucketACLs -> Bool)
-> (SetBucketACLs -> SetBucketACLs -> Bool) -> Eq SetBucketACLs
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SetBucketACLs -> SetBucketACLs -> Bool
$c/= :: SetBucketACLs -> SetBucketACLs -> Bool
== :: SetBucketACLs -> SetBucketACLs -> Bool
$c== :: SetBucketACLs -> SetBucketACLs -> Bool
Eq, (forall x. SetBucketACLs -> Rep SetBucketACLs x)
-> (forall x. Rep SetBucketACLs x -> SetBucketACLs)
-> Generic SetBucketACLs
forall x. Rep SetBucketACLs x -> SetBucketACLs
forall x. SetBucketACLs -> Rep SetBucketACLs x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SetBucketACLs x -> SetBucketACLs
$cfrom :: forall x. SetBucketACLs -> Rep SetBucketACLs x
Generic )

type SetBucketACLsResponse = ()

instance MonadSpaces m => Action m SetBucketACLs where
    type ConsumedResponse SetBucketACLs = SetBucketACLsResponse

    buildRequest :: SetBucketACLs -> m SpacesRequestBuilder
buildRequest sba :: SetBucketACLs
sba@SetBucketACLs { [Grant]
Owner
Bucket
owner :: Owner
acls :: [Grant]
bucket :: Bucket
$sel:owner:SetBucketACLs :: SetBucketACLs -> Owner
$sel:acls:SetBucketACLs :: SetBucketACLs -> [Grant]
$sel:bucket:SetBucketACLs :: SetBucketACLs -> Bucket
.. } = do
        Spaces
spaces <- m Spaces
forall r (m :: * -> *). MonadReader r m => m r
ask
        SpacesRequestBuilder -> m SpacesRequestBuilder
forall (m :: * -> *) a. Monad m => a -> m a
return SpacesRequestBuilder :: Spaces
-> Maybe RequestBody
-> Maybe Method
-> [Header]
-> Maybe Bucket
-> Maybe Object
-> Maybe Query
-> Maybe Query
-> Maybe Region
-> SpacesRequestBuilder
SpacesRequestBuilder
               { $sel:bucket:SpacesRequestBuilder :: Maybe Bucket
bucket         = Bucket -> Maybe Bucket
forall a. a -> Maybe a
Just Bucket
bucket
               , $sel:method:SpacesRequestBuilder :: Maybe Method
method         = Method -> Maybe Method
forall a. a -> Maybe a
Just Method
PUT
               , $sel:object:SpacesRequestBuilder :: Maybe Object
object         = Maybe Object
forall a. Maybe a
Nothing
               , $sel:overrideRegion:SpacesRequestBuilder :: Maybe Region
overrideRegion = Maybe Region
forall a. Maybe a
Nothing
               , $sel:queryString:SpacesRequestBuilder :: Maybe Query
queryString    = Maybe Query
forall a. Maybe a
Nothing
               , $sel:headers:SpacesRequestBuilder :: [Header]
headers        = [Header]
forall a. Monoid a => a
mempty
               , $sel:body:SpacesRequestBuilder :: Maybe RequestBody
body           = RequestBody -> Maybe RequestBody
forall a. a -> Maybe a
Just (RequestBody -> Maybe RequestBody)
-> (ByteString -> RequestBody) -> ByteString -> Maybe RequestBody
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> RequestBody
RequestBodyLBS (ByteString -> Maybe RequestBody)
-> ByteString -> Maybe RequestBody
forall a b. (a -> b) -> a -> b
$ SetBucketACLs -> ByteString
forall r.
(HasField' "owner" r Owner, HasField' "acls" r [Grant]) =>
r -> ByteString
writeACLSetter SetBucketACLs
sba
               , $sel:subresources:SpacesRequestBuilder :: Maybe Query
subresources   = Query -> Maybe Query
forall a. a -> Maybe a
Just
                     (Query -> Maybe Query) -> Query -> Maybe Query
forall a b. (a -> b) -> a -> b
$ Query -> Query
forall a. QueryLike a => a -> Query
H.toQuery [ ( ByteString
"acl" :: ByteString
                                   , Maybe ByteString
forall a. Maybe a
Nothing :: Maybe ByteString
                                   )
                                 ]
               , Spaces
$sel:spaces:SpacesRequestBuilder :: Spaces
spaces :: Spaces
..
               }

    consumeResponse :: RawResponse m -> m (ConsumedResponse SetBucketACLs)
consumeResponse RawResponse m
_ = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()