{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- Handles decoding of HTTP messages.
-- 
-- t'GI.Soup.Objects.ContentDecoder.ContentDecoder' handles adding the \"Accept-Encoding\" header on
-- outgoing messages, and processing the \"Content-Encoding\" header on
-- incoming ones. Currently it supports the \"gzip\", \"deflate\", and \"br\"
-- content codings.
-- 
-- A t'GI.Soup.Objects.ContentDecoder.ContentDecoder' will automatically be
-- added to the session by default. (You can use
-- [method/@session@/.remove_feature_by_type] if you don\'t
-- want this.)
-- 
-- If t'GI.Soup.Objects.ContentDecoder.ContentDecoder' successfully decodes the Content-Encoding,
-- the message body will contain the decoded data; however, the message headers
-- will be unchanged (and so \"Content-Encoding\" will still be present,
-- \"Content-Length\" will describe the original encoded length, etc).
-- 
-- If \"Content-Encoding\" contains any encoding types that
-- t'GI.Soup.Objects.ContentDecoder.ContentDecoder' doesn\'t recognize, then none of the encodings
-- will be decoded.
-- 
-- (Note that currently there is no way to (automatically) use
-- Content-Encoding when sending a request body, or to pick specific
-- encoding types to support.)

#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif

module GI.Soup.Objects.ContentDecoder
    ( 

-- * Exported types
    ContentDecoder(..)                      ,
    IsContentDecoder                        ,
    toContentDecoder                        ,


 -- * Methods
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [bindProperty]("GI.GObject.Objects.Object#g:method:bindProperty"), [bindPropertyFull]("GI.GObject.Objects.Object#g:method:bindPropertyFull"), [forceFloating]("GI.GObject.Objects.Object#g:method:forceFloating"), [freezeNotify]("GI.GObject.Objects.Object#g:method:freezeNotify"), [getv]("GI.GObject.Objects.Object#g:method:getv"), [isFloating]("GI.GObject.Objects.Object#g:method:isFloating"), [notify]("GI.GObject.Objects.Object#g:method:notify"), [notifyByPspec]("GI.GObject.Objects.Object#g:method:notifyByPspec"), [ref]("GI.GObject.Objects.Object#g:method:ref"), [refSink]("GI.GObject.Objects.Object#g:method:refSink"), [runDispose]("GI.GObject.Objects.Object#g:method:runDispose"), [stealData]("GI.GObject.Objects.Object#g:method:stealData"), [stealQdata]("GI.GObject.Objects.Object#g:method:stealQdata"), [thawNotify]("GI.GObject.Objects.Object#g:method:thawNotify"), [unref]("GI.GObject.Objects.Object#g:method:unref"), [watchClosure]("GI.GObject.Objects.Object#g:method:watchClosure").
-- 
-- ==== Getters
-- [getData]("GI.GObject.Objects.Object#g:method:getData"), [getProperty]("GI.GObject.Objects.Object#g:method:getProperty"), [getQdata]("GI.GObject.Objects.Object#g:method:getQdata").
-- 
-- ==== Setters
-- [setData]("GI.GObject.Objects.Object#g:method:setData"), [setDataFull]("GI.GObject.Objects.Object#g:method:setDataFull"), [setProperty]("GI.GObject.Objects.Object#g:method:setProperty").

#if defined(ENABLE_OVERLOADING)
    ResolveContentDecoderMethod             ,
#endif



    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.BasicTypes as B.Types
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GArray as B.GArray
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GHashTable as B.GHT
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
import qualified Data.Coerce as Coerce
import qualified Data.Text as T
import qualified Data.Kind as DK
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL
import qualified GHC.Records as R

import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Soup.Interfaces.SessionFeature as Soup.SessionFeature

-- | Memory-managed wrapper type.
newtype ContentDecoder = ContentDecoder (SP.ManagedPtr ContentDecoder)
    deriving (ContentDecoder -> ContentDecoder -> Bool
(ContentDecoder -> ContentDecoder -> Bool)
-> (ContentDecoder -> ContentDecoder -> Bool) -> Eq ContentDecoder
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ContentDecoder -> ContentDecoder -> Bool
== :: ContentDecoder -> ContentDecoder -> Bool
$c/= :: ContentDecoder -> ContentDecoder -> Bool
/= :: ContentDecoder -> ContentDecoder -> Bool
Eq)

instance SP.ManagedPtrNewtype ContentDecoder where
    toManagedPtr :: ContentDecoder -> ManagedPtr ContentDecoder
toManagedPtr (ContentDecoder ManagedPtr ContentDecoder
p) = ManagedPtr ContentDecoder
p

foreign import ccall "soup_content_decoder_get_type"
    c_soup_content_decoder_get_type :: IO B.Types.GType

instance B.Types.TypedObject ContentDecoder where
    glibType :: IO GType
glibType = IO GType
c_soup_content_decoder_get_type

instance B.Types.GObject ContentDecoder

-- | Type class for types which can be safely cast to `ContentDecoder`, for instance with `toContentDecoder`.
class (SP.GObject o, O.IsDescendantOf ContentDecoder o) => IsContentDecoder o
instance (SP.GObject o, O.IsDescendantOf ContentDecoder o) => IsContentDecoder o

instance O.HasParentTypes ContentDecoder
type instance O.ParentTypes ContentDecoder = '[GObject.Object.Object, Soup.SessionFeature.SessionFeature]

-- | Cast to `ContentDecoder`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toContentDecoder :: (MIO.MonadIO m, IsContentDecoder o) => o -> m ContentDecoder
toContentDecoder :: forall (m :: * -> *) o.
(MonadIO m, IsContentDecoder o) =>
o -> m ContentDecoder
toContentDecoder = IO ContentDecoder -> m ContentDecoder
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
MIO.liftIO (IO ContentDecoder -> m ContentDecoder)
-> (o -> IO ContentDecoder) -> o -> m ContentDecoder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr ContentDecoder -> ContentDecoder)
-> o -> IO ContentDecoder
forall o o'.
(HasCallStack, ManagedPtrNewtype o, TypedObject o,
 ManagedPtrNewtype o', TypedObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
B.ManagedPtr.unsafeCastTo ManagedPtr ContentDecoder -> ContentDecoder
ContentDecoder

-- | Convert 'ContentDecoder' to and from 'Data.GI.Base.GValue.GValue'. See 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue (Maybe ContentDecoder) where
    gvalueGType_ :: IO GType
gvalueGType_ = IO GType
c_soup_content_decoder_get_type
    gvalueSet_ :: Ptr GValue -> Maybe ContentDecoder -> IO ()
gvalueSet_ Ptr GValue
gv Maybe ContentDecoder
P.Nothing = Ptr GValue -> Ptr ContentDecoder -> IO ()
forall a. GObject a => Ptr GValue -> Ptr a -> IO ()
B.GValue.set_object Ptr GValue
gv (Ptr ContentDecoder
forall a. Ptr a
FP.nullPtr :: FP.Ptr ContentDecoder)
    gvalueSet_ Ptr GValue
gv (P.Just ContentDecoder
obj) = ContentDecoder -> (Ptr ContentDecoder -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr ContentDecoder
obj (Ptr GValue -> Ptr ContentDecoder -> IO ()
forall a. GObject a => Ptr GValue -> Ptr a -> IO ()
B.GValue.set_object Ptr GValue
gv)
    gvalueGet_ :: Ptr GValue -> IO (Maybe ContentDecoder)
gvalueGet_ Ptr GValue
gv = do
        Ptr ContentDecoder
ptr <- Ptr GValue -> IO (Ptr ContentDecoder)
forall a. GObject a => Ptr GValue -> IO (Ptr a)
B.GValue.get_object Ptr GValue
gv :: IO (FP.Ptr ContentDecoder)
        if Ptr ContentDecoder
ptr Ptr ContentDecoder -> Ptr ContentDecoder -> Bool
forall a. Eq a => a -> a -> Bool
/= Ptr ContentDecoder
forall a. Ptr a
FP.nullPtr
        then ContentDecoder -> Maybe ContentDecoder
forall a. a -> Maybe a
P.Just (ContentDecoder -> Maybe ContentDecoder)
-> IO ContentDecoder -> IO (Maybe ContentDecoder)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ManagedPtr ContentDecoder -> ContentDecoder)
-> Ptr ContentDecoder -> IO ContentDecoder
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
B.ManagedPtr.newObject ManagedPtr ContentDecoder -> ContentDecoder
ContentDecoder Ptr ContentDecoder
ptr
        else Maybe ContentDecoder -> IO (Maybe ContentDecoder)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe ContentDecoder
forall a. Maybe a
P.Nothing
        
    

#if defined(ENABLE_OVERLOADING)
type family ResolveContentDecoderMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
    ResolveContentDecoderMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveContentDecoderMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveContentDecoderMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveContentDecoderMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveContentDecoderMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveContentDecoderMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveContentDecoderMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveContentDecoderMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveContentDecoderMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveContentDecoderMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveContentDecoderMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveContentDecoderMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveContentDecoderMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveContentDecoderMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveContentDecoderMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveContentDecoderMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveContentDecoderMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveContentDecoderMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveContentDecoderMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveContentDecoderMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveContentDecoderMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveContentDecoderMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveContentDecoderMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveContentDecoderMethod t ContentDecoder, O.OverloadedMethod info ContentDecoder p) => OL.IsLabel t (ContentDecoder -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#if MIN_VERSION_base(4,13,0)
instance (info ~ ResolveContentDecoderMethod t ContentDecoder, O.OverloadedMethod info ContentDecoder p, R.HasField t ContentDecoder p) => R.HasField t ContentDecoder p where
    getField = O.overloadedMethod @info

#endif

instance (info ~ ResolveContentDecoderMethod t ContentDecoder, O.OverloadedMethodInfo info ContentDecoder) => OL.IsLabel t (O.MethodProxy info ContentDecoder) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.MethodProxy
#else
    fromLabel _ = O.MethodProxy
#endif

#endif

#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList ContentDecoder
type instance O.AttributeList ContentDecoder = ContentDecoderAttributeList
type ContentDecoderAttributeList = ('[ ] :: [(Symbol, DK.Type)])
#endif

#if defined(ENABLE_OVERLOADING)
#endif

#if defined(ENABLE_OVERLOADING)
type instance O.SignalList ContentDecoder = ContentDecoderSignalList
type ContentDecoderSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, DK.Type)])

#endif