-- SPDX-FileCopyrightText: 2022-2024 Stephan Barth <stephan.barth@ Gregor Kleen <gregor.kleen@ifi.lmu.de>
--
-- SPDX-License-Identifier: AGPL-3.0-or-later

{-# OPTIONS_GHC -fno-warn-orphans #-}

module Network.Minio.Instances
  (
  ) where

import ClassyPrelude

import Network.Minio

import qualified UnliftIO.Exception as UnliftIO
import Control.Monad.Catch

                  -- fromJSON, withObject, withScientific
                  -- , (.!=), (.:?)
import Data.Aeson (
                  FromJSON(..)
                  )

import Data.ByteArray

instance MonadThrow Minio where
  throwM = UnliftIO.throwIO

instance MonadCatch Minio where
  catch = UnliftIO.catch

instance MonadMask Minio where
  mask = UnliftIO.mask
  uninterruptibleMask = UnliftIO.uninterruptibleMask
  generalBracket acq rel inner = withUnliftIO $ \UnliftIO{..} -> generalBracket (unliftIO acq) ((unliftIO .) . rel) $ unliftIO . inner

instance FromJSON ScrubbedBytes where
  parseJSON = error "instance FromJSON ScrubbedBytes used but not implemented; implementation was neccessary due to version bump but cannot defined directly as intended, as ScrubbedBytes wants to take care that data cannot remain in memory after free, but Aeson does not care on loading. Hence, not implemented right now."
  -- do
  --  pj <- parseJSON x
  --  return $ 

deriving newtype instance FromJSON AccessKey
deriving newtype instance FromJSON SecretKey
