module Registry.S3.DocumentTemplate.DocumentTemplateS3 where

import qualified Data.ByteString.Char8 as BS
import qualified Data.UUID as U

import Registry.Model.Context.AppContext
import Registry.Model.Context.ContextLenses ()
import Shared.S3.Common
import Shared.Util.String (f')

folderName = "templates"

retrieveAsset :: String -> U.UUID -> AppContextM BS.ByteString
retrieveAsset documentTemplateId assetUuid = createGetObjectFn (f' "%s/%s/%s" [folderName, documentTemplateId, U.toString assetUuid])

putAsset :: String -> U.UUID -> String -> BS.ByteString -> AppContextM String
putAsset documentTemplateId assetUuid contentType = createPutObjectFn (f' "%s/%s/%s" [folderName, documentTemplateId, U.toString assetUuid]) (Just contentType) Nothing

makePublicLink :: String -> U.UUID -> AppContextM String
makePublicLink documentTemplateId assetUuid = createMakePublicLink (f' "%s/%s/%s" [folderName, documentTemplateId, U.toString assetUuid])

removeAssets :: String -> AppContextM ()
removeAssets documentTemplateId = createRemoveObjectFn (f' "%s/%s" [folderName, documentTemplateId])

removeAsset :: String -> U.UUID -> AppContextM ()
removeAsset documentTemplateId assetUuid = createRemoveObjectFn (f' "%s/%s/%s" [folderName, documentTemplateId, U.toString assetUuid])

makeBucket :: AppContextM ()
makeBucket = createMakeBucketFn

purgeBucket :: AppContextM ()
purgeBucket = createPurgeBucketFn

removeBucket :: AppContextM ()
removeBucket = createRemoveBucketFn

module Registry.S3.DocumentTemplate.DocumentTemplateS3 where

import qualified Data.ByteString.Char8 as BS
import qualified Data.UUID as U

import Registry.Model.Context.AppContext
import Registry.Model.Context.ContextLenses ()
import Shared.S3.Common
import Shared.Util.String (f')

folderName = "templates"

retrieveAsset :: String -> U.UUID -> AppContextM BS.ByteString
retrieveAsset documentTemplateId assetUuid = createGetObjectFn (f' "%s/%s/%s" [folderName, documentTemplateId, U.toString assetUuid])

putAsset :: String -> U.UUID -> String -> BS.ByteString -> AppContextM String
putAsset documentTemplateId assetUuid contentType = createPutObjectFn (f' "%s/%s/%s" [folderName, documentTemplateId, U.toString assetUuid]) (Just contentType) Nothing

makePublicLink :: String -> U.UUID -> AppContextM String
makePublicLink documentTemplateId assetUuid = createMakePublicLink (f' "%s/%s/%s" [folderName, documentTemplateId, U.toString assetUuid])

removeAssets :: String -> AppContextM ()
removeAssets documentTemplateId = createRemoveObjectFn (f' "%s/%s" [folderName, documentTemplateId])

removeAsset :: String -> U.UUID -> AppContextM ()
removeAsset documentTemplateId assetUuid = createRemoveObjectFn (f' "%s/%s/%s" [folderName, documentTemplateId, U.toString assetUuid])

makeBucket :: AppContextM ()
makeBucket = createMakeBucketFn

purgeBucket :: AppContextM ()
purgeBucket = createPurgeBucketFn

removeBucket :: AppContextM ()
removeBucket = createRemoveBucketFn
