{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

An object that implement some sort of optional feature for
'GI.Soup.Objects.Session.Session'.
-}

module GI.Soup.Interfaces.SessionFeature
    ( 

-- * Exported types
    SessionFeature(..)                      ,
    noSessionFeature                        ,
    IsSessionFeature                        ,
    toSessionFeature                        ,


 -- * Methods
-- ** addFeature #method:addFeature#
    SessionFeatureAddFeatureMethodInfo      ,
    sessionFeatureAddFeature                ,


-- ** attach #method:attach#
    SessionFeatureAttachMethodInfo          ,
    sessionFeatureAttach                    ,


-- ** detach #method:detach#
    SessionFeatureDetachMethodInfo          ,
    sessionFeatureDetach                    ,


-- ** hasFeature #method:hasFeature#
    SessionFeatureHasFeatureMethodInfo      ,
    sessionFeatureHasFeature                ,


-- ** removeFeature #method:removeFeature#
    SessionFeatureRemoveFeatureMethodInfo   ,
    sessionFeatureRemoveFeature             ,




    ) 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.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP

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

-- interface SessionFeature 
newtype SessionFeature = SessionFeature (ManagedPtr SessionFeature)
noSessionFeature :: Maybe SessionFeature
noSessionFeature = Nothing

type family ResolveSessionFeatureMethod (t :: Symbol) (o :: *) :: * where
    ResolveSessionFeatureMethod "addFeature" o = SessionFeatureAddFeatureMethodInfo
    ResolveSessionFeatureMethod "attach" o = SessionFeatureAttachMethodInfo
    ResolveSessionFeatureMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveSessionFeatureMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveSessionFeatureMethod "detach" o = SessionFeatureDetachMethodInfo
    ResolveSessionFeatureMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveSessionFeatureMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveSessionFeatureMethod "hasFeature" o = SessionFeatureHasFeatureMethodInfo
    ResolveSessionFeatureMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveSessionFeatureMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveSessionFeatureMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveSessionFeatureMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveSessionFeatureMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveSessionFeatureMethod "removeFeature" o = SessionFeatureRemoveFeatureMethodInfo
    ResolveSessionFeatureMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveSessionFeatureMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveSessionFeatureMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveSessionFeatureMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveSessionFeatureMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveSessionFeatureMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveSessionFeatureMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveSessionFeatureMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveSessionFeatureMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveSessionFeatureMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveSessionFeatureMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveSessionFeatureMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveSessionFeatureMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveSessionFeatureMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveSessionFeatureMethod t SessionFeature, O.MethodInfo info SessionFeature p) => O.IsLabelProxy t (SessionFeature -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveSessionFeatureMethod t SessionFeature, O.MethodInfo info SessionFeature p) => O.IsLabel t (SessionFeature -> p) where
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

instance O.HasAttributeList SessionFeature
type instance O.AttributeList SessionFeature = SessionFeatureAttributeList
type SessionFeatureAttributeList = ('[ ] :: [(Symbol, *)])

type instance O.SignalList SessionFeature = SessionFeatureSignalList
type SessionFeatureSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

foreign import ccall "soup_session_feature_get_type"
    c_soup_session_feature_get_type :: IO GType

instance GObject SessionFeature where
    gobjectType _ = c_soup_session_feature_get_type
    

class GObject o => IsSessionFeature o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError SessionFeature a) =>
    IsSessionFeature a
#endif
instance IsSessionFeature SessionFeature
instance GObject.Object.IsObject SessionFeature

toSessionFeature :: IsSessionFeature o => o -> IO SessionFeature
toSessionFeature = unsafeCastTo SessionFeature

-- method SessionFeature::add_feature
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "feature", argType = TInterface (Name {namespace = "Soup", name = "SessionFeature"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the \"base\" feature", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "type", argType = TBasicType TGType, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GType of a \"sub-feature\"", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "soup_session_feature_add_feature" soup_session_feature_add_feature :: 
    Ptr SessionFeature ->                   -- feature : TInterface (Name {namespace = "Soup", name = "SessionFeature"})
    CGType ->                               -- type : TBasicType TGType
    IO CInt

{- |
Adds a \"sub-feature\" of type /@type@/ to the base feature /@feature@/.
This is used for features that can be extended with multiple
different types. Eg, the authentication manager can be extended
with subtypes of 'GI.Soup.Objects.Auth.Auth'.

@since 2.34
-}
sessionFeatureAddFeature ::
    (B.CallStack.HasCallStack, MonadIO m, IsSessionFeature a) =>
    a
    {- ^ /@feature@/: the \"base\" feature -}
    -> GType
    {- ^ /@type@/: the 'GType' of a \"sub-feature\" -}
    -> m Bool
    {- ^ __Returns:__ 'True' if /@feature@/ accepted /@type@/ as a subfeature. -}
sessionFeatureAddFeature feature type_ = liftIO $ do
    feature' <- unsafeManagedPtrCastPtr feature
    let type_' = gtypeToCGType type_
    result <- soup_session_feature_add_feature feature' type_'
    let result' = (/= 0) result
    touchManagedPtr feature
    return result'

data SessionFeatureAddFeatureMethodInfo
instance (signature ~ (GType -> m Bool), MonadIO m, IsSessionFeature a) => O.MethodInfo SessionFeatureAddFeatureMethodInfo a signature where
    overloadedMethod _ = sessionFeatureAddFeature

-- method SessionFeature::attach
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "feature", argType = TInterface (Name {namespace = "Soup", name = "SessionFeature"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "session", argType = TInterface (Name {namespace = "Soup", name = "Session"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_session_feature_attach" soup_session_feature_attach :: 
    Ptr SessionFeature ->                   -- feature : TInterface (Name {namespace = "Soup", name = "SessionFeature"})
    Ptr Soup.Session.Session ->             -- session : TInterface (Name {namespace = "Soup", name = "Session"})
    IO ()

{- |
/No description available in the introspection data./
-}
sessionFeatureAttach ::
    (B.CallStack.HasCallStack, MonadIO m, IsSessionFeature a, Soup.Session.IsSession b) =>
    a
    -> b
    -> m ()
sessionFeatureAttach feature session = liftIO $ do
    feature' <- unsafeManagedPtrCastPtr feature
    session' <- unsafeManagedPtrCastPtr session
    soup_session_feature_attach feature' session'
    touchManagedPtr feature
    touchManagedPtr session
    return ()

data SessionFeatureAttachMethodInfo
instance (signature ~ (b -> m ()), MonadIO m, IsSessionFeature a, Soup.Session.IsSession b) => O.MethodInfo SessionFeatureAttachMethodInfo a signature where
    overloadedMethod _ = sessionFeatureAttach

-- method SessionFeature::detach
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "feature", argType = TInterface (Name {namespace = "Soup", name = "SessionFeature"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "session", argType = TInterface (Name {namespace = "Soup", name = "Session"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_session_feature_detach" soup_session_feature_detach :: 
    Ptr SessionFeature ->                   -- feature : TInterface (Name {namespace = "Soup", name = "SessionFeature"})
    Ptr Soup.Session.Session ->             -- session : TInterface (Name {namespace = "Soup", name = "Session"})
    IO ()

{- |
/No description available in the introspection data./
-}
sessionFeatureDetach ::
    (B.CallStack.HasCallStack, MonadIO m, IsSessionFeature a, Soup.Session.IsSession b) =>
    a
    -> b
    -> m ()
sessionFeatureDetach feature session = liftIO $ do
    feature' <- unsafeManagedPtrCastPtr feature
    session' <- unsafeManagedPtrCastPtr session
    soup_session_feature_detach feature' session'
    touchManagedPtr feature
    touchManagedPtr session
    return ()

data SessionFeatureDetachMethodInfo
instance (signature ~ (b -> m ()), MonadIO m, IsSessionFeature a, Soup.Session.IsSession b) => O.MethodInfo SessionFeatureDetachMethodInfo a signature where
    overloadedMethod _ = sessionFeatureDetach

-- method SessionFeature::has_feature
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "feature", argType = TInterface (Name {namespace = "Soup", name = "SessionFeature"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the \"base\" feature", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "type", argType = TBasicType TGType, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GType of a \"sub-feature\"", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "soup_session_feature_has_feature" soup_session_feature_has_feature :: 
    Ptr SessionFeature ->                   -- feature : TInterface (Name {namespace = "Soup", name = "SessionFeature"})
    CGType ->                               -- type : TBasicType TGType
    IO CInt

{- |
Tests if /@feature@/ has a \"sub-feature\" of type /@type@/. See
'GI.Soup.Interfaces.SessionFeature.sessionFeatureAddFeature'.

@since 2.34
-}
sessionFeatureHasFeature ::
    (B.CallStack.HasCallStack, MonadIO m, IsSessionFeature a) =>
    a
    {- ^ /@feature@/: the \"base\" feature -}
    -> GType
    {- ^ /@type@/: the 'GType' of a \"sub-feature\" -}
    -> m Bool
    {- ^ __Returns:__ 'True' if /@feature@/ has a subfeature of type /@type@/ -}
sessionFeatureHasFeature feature type_ = liftIO $ do
    feature' <- unsafeManagedPtrCastPtr feature
    let type_' = gtypeToCGType type_
    result <- soup_session_feature_has_feature feature' type_'
    let result' = (/= 0) result
    touchManagedPtr feature
    return result'

data SessionFeatureHasFeatureMethodInfo
instance (signature ~ (GType -> m Bool), MonadIO m, IsSessionFeature a) => O.MethodInfo SessionFeatureHasFeatureMethodInfo a signature where
    overloadedMethod _ = sessionFeatureHasFeature

-- method SessionFeature::remove_feature
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "feature", argType = TInterface (Name {namespace = "Soup", name = "SessionFeature"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the \"base\" feature", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "type", argType = TBasicType TGType, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GType of a \"sub-feature\"", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "soup_session_feature_remove_feature" soup_session_feature_remove_feature :: 
    Ptr SessionFeature ->                   -- feature : TInterface (Name {namespace = "Soup", name = "SessionFeature"})
    CGType ->                               -- type : TBasicType TGType
    IO CInt

{- |
Removes the \"sub-feature\" of type /@type@/ from the base feature
/@feature@/. See 'GI.Soup.Interfaces.SessionFeature.sessionFeatureAddFeature'.

@since 2.34
-}
sessionFeatureRemoveFeature ::
    (B.CallStack.HasCallStack, MonadIO m, IsSessionFeature a) =>
    a
    {- ^ /@feature@/: the \"base\" feature -}
    -> GType
    {- ^ /@type@/: the 'GType' of a \"sub-feature\" -}
    -> m Bool
    {- ^ __Returns:__ 'True' if /@type@/ was removed from /@feature@/ -}
sessionFeatureRemoveFeature feature type_ = liftIO $ do
    feature' <- unsafeManagedPtrCastPtr feature
    let type_' = gtypeToCGType type_
    result <- soup_session_feature_remove_feature feature' type_'
    let result' = (/= 0) result
    touchManagedPtr feature
    return result'

data SessionFeatureRemoveFeatureMethodInfo
instance (signature ~ (GType -> m Bool), MonadIO m, IsSessionFeature a) => O.MethodInfo SessionFeatureRemoveFeatureMethodInfo a signature where
    overloadedMethod _ = sessionFeatureRemoveFeature