{-# 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.SetObjectACLs
-- Copyright   : (c) 2021 Rory Tyler Hayford
-- License     : BSD-3-Clause
-- Maintainer  : rory.hayford@protonmail.com
-- Stability   : experimental
-- Portability : GHC
--
module Network.DO.Spaces.Actions.SetObjectACLs
    ( SetObjectACLs(..)
    , SetObjectACLsResponse
    ) 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
                 , Object
                 , Owner
                 , SpacesRequestBuilder(..)
                 )
import           Network.DO.Spaces.Utils     ( writeACLSetter )
import           Network.HTTP.Client.Conduit ( RequestBody(RequestBodyLBS) )
import qualified Network.HTTP.Types          as H

-- | Get the full Access Control List associated with a 'Bucket'
data SetObjectACLs = SetObjectACLs
    { SetObjectACLs -> Bucket
bucket :: Bucket
    , SetObjectACLs -> Object
object :: Object
    , SetObjectACLs -> Owner
owner  :: Owner -- ^ The object owner
    , SetObjectACLs -> [Grant]
acls   :: [Grant]
    }
    deriving ( Int -> SetObjectACLs -> ShowS
[SetObjectACLs] -> ShowS
SetObjectACLs -> String
(Int -> SetObjectACLs -> ShowS)
-> (SetObjectACLs -> String)
-> ([SetObjectACLs] -> ShowS)
-> Show SetObjectACLs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SetObjectACLs] -> ShowS
$cshowList :: [SetObjectACLs] -> ShowS
show :: SetObjectACLs -> String
$cshow :: SetObjectACLs -> String
showsPrec :: Int -> SetObjectACLs -> ShowS
$cshowsPrec :: Int -> SetObjectACLs -> ShowS
Show, SetObjectACLs -> SetObjectACLs -> Bool
(SetObjectACLs -> SetObjectACLs -> Bool)
-> (SetObjectACLs -> SetObjectACLs -> Bool) -> Eq SetObjectACLs
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SetObjectACLs -> SetObjectACLs -> Bool
$c/= :: SetObjectACLs -> SetObjectACLs -> Bool
== :: SetObjectACLs -> SetObjectACLs -> Bool
$c== :: SetObjectACLs -> SetObjectACLs -> Bool
Eq, (forall x. SetObjectACLs -> Rep SetObjectACLs x)
-> (forall x. Rep SetObjectACLs x -> SetObjectACLs)
-> Generic SetObjectACLs
forall x. Rep SetObjectACLs x -> SetObjectACLs
forall x. SetObjectACLs -> Rep SetObjectACLs x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SetObjectACLs x -> SetObjectACLs
$cfrom :: forall x. SetObjectACLs -> Rep SetObjectACLs x
Generic )

type SetObjectACLsResponse = ()

instance MonadSpaces m => Action m SetObjectACLs where
    type ConsumedResponse SetObjectACLs = SetObjectACLsResponse

    buildRequest :: SetObjectACLs -> m SpacesRequestBuilder
buildRequest soa :: SetObjectACLs
soa@SetObjectACLs { [Grant]
Owner
Object
Bucket
acls :: [Grant]
owner :: Owner
object :: Object
bucket :: Bucket
$sel:acls:SetObjectACLs :: SetObjectACLs -> [Grant]
$sel:owner:SetObjectACLs :: SetObjectACLs -> Owner
$sel:object:SetObjectACLs :: SetObjectACLs -> Object
$sel:bucket:SetObjectACLs :: SetObjectACLs -> 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:object:SpacesRequestBuilder :: Maybe Object
object         = Object -> Maybe Object
forall a. a -> Maybe a
Just Object
object
               , $sel:method:SpacesRequestBuilder :: Maybe Method
method         = Method -> Maybe Method
forall a. a -> Maybe a
Just Method
PUT
               , $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
$ SetObjectACLs -> ByteString
forall r.
(HasField' "owner" r Owner, HasField' "acls" r [Grant]) =>
r -> ByteString
writeACLSetter SetObjectACLs
soa
               , $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: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 SetObjectACLs)
consumeResponse RawResponse m
_ = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()