{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- An event hook that runs a GClosure, synchronously.

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

module GI.Wp.Objects.SimpleEventHook
    ( 

-- * Exported types
    SimpleEventHook(..)                     ,
    IsSimpleEventHook                       ,
    toSimpleEventHook                       ,


 -- * Methods
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [addInterestFull]("GI.Wp.Objects.InterestEventHook#g:method:addInterestFull"), [bindProperty]("GI.GObject.Objects.Object#g:method:bindProperty"), [bindPropertyFull]("GI.GObject.Objects.Object#g:method:bindPropertyFull"), [finish]("GI.Wp.Objects.EventHook#g:method:finish"), [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"), [run]("GI.Wp.Objects.EventHook#g:method:run"), [runDispose]("GI.GObject.Objects.Object#g:method:runDispose"), [runsForEvent]("GI.Wp.Objects.EventHook#g:method:runsForEvent"), [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"), [getMatchingEventTypes]("GI.Wp.Objects.EventHook#g:method:getMatchingEventTypes"), [getName]("GI.Wp.Objects.EventHook#g:method:getName"), [getProperty]("GI.GObject.Objects.Object#g:method:getProperty"), [getQdata]("GI.GObject.Objects.Object#g:method:getQdata"), [getRunsAfterHooks]("GI.Wp.Objects.EventHook#g:method:getRunsAfterHooks"), [getRunsBeforeHooks]("GI.Wp.Objects.EventHook#g:method:getRunsBeforeHooks").
-- 
-- ==== 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)
    ResolveSimpleEventHookMethod            ,
#endif

-- ** new #method:new#

    simpleEventHookNew                      ,




 -- * Properties


-- ** closure #attr:closure#
-- | /No description available in the introspection data./

#if defined(ENABLE_OVERLOADING)
    SimpleEventHookClosurePropertyInfo      ,
#endif
    constructSimpleEventHookClosure         ,
#if defined(ENABLE_OVERLOADING)
    simpleEventHookClosure                  ,
#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 Data.Word as DW
import qualified Data.Int as DI
import qualified System.Posix.Types as SPT
import qualified Foreign.C.Types as FCT

-- Workaround for https://gitlab.haskell.org/ghc/ghc/-/issues/23392
#if MIN_VERSION_base(4,18,0)
import qualified GI.GLib.Callbacks as GLib.Callbacks
import qualified GI.GLib.Structs.MainContext as GLib.MainContext
import qualified GI.GLib.Structs.Source as GLib.Source
import qualified GI.GObject.Objects.Object as GObject.Object
import qualified GI.Gio.Callbacks as Gio.Callbacks
import qualified GI.Gio.Interfaces.AsyncResult as Gio.AsyncResult
import qualified GI.Gio.Objects.Cancellable as Gio.Cancellable
import qualified GI.Wp.Callbacks as Wp.Callbacks
import {-# SOURCE #-} qualified GI.Wp.Enums as Wp.Enums
import {-# SOURCE #-} qualified GI.Wp.Flags as Wp.Flags
import {-# SOURCE #-} qualified GI.Wp.Objects.Conf as Wp.Conf
import {-# SOURCE #-} qualified GI.Wp.Objects.Core as Wp.Core
import {-# SOURCE #-} qualified GI.Wp.Objects.EventDispatcher as Wp.EventDispatcher
import {-# SOURCE #-} qualified GI.Wp.Objects.EventHook as Wp.EventHook
import {-# SOURCE #-} qualified GI.Wp.Objects.InterestEventHook as Wp.InterestEventHook
import {-# SOURCE #-} qualified GI.Wp.Objects.Object as Wp.Object
import {-# SOURCE #-} qualified GI.Wp.Objects.ObjectManager as Wp.ObjectManager
import {-# SOURCE #-} qualified GI.Wp.Structs.Event as Wp.Event
import {-# SOURCE #-} qualified GI.Wp.Structs.Iterator as Wp.Iterator
import {-# SOURCE #-} qualified GI.Wp.Structs.IteratorMethods as Wp.IteratorMethods
import {-# SOURCE #-} qualified GI.Wp.Structs.ObjectInterest as Wp.ObjectInterest
import {-# SOURCE #-} qualified GI.Wp.Structs.Properties as Wp.Properties
import {-# SOURCE #-} qualified GI.Wp.Structs.SpaJson as Wp.SpaJson

#else
import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Wp.Objects.EventHook as Wp.EventHook
import {-# SOURCE #-} qualified GI.Wp.Objects.InterestEventHook as Wp.InterestEventHook

#endif

-- | Memory-managed wrapper type.
newtype SimpleEventHook = SimpleEventHook (SP.ManagedPtr SimpleEventHook)
    deriving (Eq)

instance SP.ManagedPtrNewtype SimpleEventHook where
    toManagedPtr (SimpleEventHook p) = p

foreign import ccall "wp_simple_event_hook_get_type"
    c_wp_simple_event_hook_get_type :: IO B.Types.GType

instance B.Types.TypedObject SimpleEventHook where
    glibType = c_wp_simple_event_hook_get_type

instance B.Types.GObject SimpleEventHook

-- | Type class for types which can be safely cast to t'SimpleEventHook', for instance with `toSimpleEventHook`.
class (SP.GObject o, O.IsDescendantOf SimpleEventHook o) => IsSimpleEventHook o
instance (SP.GObject o, O.IsDescendantOf SimpleEventHook o) => IsSimpleEventHook o

instance O.HasParentTypes SimpleEventHook
type instance O.ParentTypes SimpleEventHook = '[Wp.InterestEventHook.InterestEventHook, Wp.EventHook.EventHook, GObject.Object.Object]

-- | Cast to t'SimpleEventHook', for types for which this is known to be safe. For general casts, use 'Data.GI.Base.ManagedPtr.castTo'.
toSimpleEventHook :: (MIO.MonadIO m, IsSimpleEventHook o) => o -> m SimpleEventHook
toSimpleEventHook = MIO.liftIO . B.ManagedPtr.unsafeCastTo SimpleEventHook

-- | Convert t'SimpleEventHook' to and from t'Data.GI.Base.GValue.GValue'. See 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue (Maybe SimpleEventHook) where
    gvalueGType_ = c_wp_simple_event_hook_get_type
    gvalueSet_ gv P.Nothing = B.GValue.set_object gv (FP.nullPtr :: FP.Ptr SimpleEventHook)
    gvalueSet_ gv (P.Just obj) = B.ManagedPtr.withManagedPtr obj (B.GValue.set_object gv)
    gvalueGet_ gv = do
        ptr <- B.GValue.get_object gv :: IO (FP.Ptr SimpleEventHook)
        if ptr /= FP.nullPtr
        then P.Just <$> B.ManagedPtr.newObject SimpleEventHook ptr
        else return P.Nothing
        
    

#if defined(ENABLE_OVERLOADING)
type family ResolveSimpleEventHookMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
    ResolveSimpleEventHookMethod "addInterestFull" o = Wp.InterestEventHook.InterestEventHookAddInterestFullMethodInfo
    ResolveSimpleEventHookMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveSimpleEventHookMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveSimpleEventHookMethod "finish" o = Wp.EventHook.EventHookFinishMethodInfo
    ResolveSimpleEventHookMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveSimpleEventHookMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveSimpleEventHookMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveSimpleEventHookMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveSimpleEventHookMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveSimpleEventHookMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveSimpleEventHookMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveSimpleEventHookMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveSimpleEventHookMethod "run" o = Wp.EventHook.EventHookRunMethodInfo
    ResolveSimpleEventHookMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveSimpleEventHookMethod "runsForEvent" o = Wp.EventHook.EventHookRunsForEventMethodInfo
    ResolveSimpleEventHookMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveSimpleEventHookMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveSimpleEventHookMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveSimpleEventHookMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveSimpleEventHookMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveSimpleEventHookMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveSimpleEventHookMethod "getMatchingEventTypes" o = Wp.EventHook.EventHookGetMatchingEventTypesMethodInfo
    ResolveSimpleEventHookMethod "getName" o = Wp.EventHook.EventHookGetNameMethodInfo
    ResolveSimpleEventHookMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveSimpleEventHookMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveSimpleEventHookMethod "getRunsAfterHooks" o = Wp.EventHook.EventHookGetRunsAfterHooksMethodInfo
    ResolveSimpleEventHookMethod "getRunsBeforeHooks" o = Wp.EventHook.EventHookGetRunsBeforeHooksMethodInfo
    ResolveSimpleEventHookMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveSimpleEventHookMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveSimpleEventHookMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveSimpleEventHookMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveSimpleEventHookMethod t SimpleEventHook, O.OverloadedMethod info SimpleEventHook p) => OL.IsLabel t (SimpleEventHook -> 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 ~ ResolveSimpleEventHookMethod t SimpleEventHook, O.OverloadedMethod info SimpleEventHook p, R.HasField t SimpleEventHook p) => R.HasField t SimpleEventHook p where
    getField = O.overloadedMethod @info

#endif

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

#endif

-- VVV Prop "closure"
   -- Type: TGClosure Nothing
   -- Flags: [PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Nothing,Nothing)

-- | Construct a t'GValueConstruct' with valid value for the “@closure@” property. This is rarely needed directly, but it is used by `Data.GI.Base.Constructible.new`.
constructSimpleEventHookClosure :: (IsSimpleEventHook o, MIO.MonadIO m) => GClosure a -> m (GValueConstruct o)
constructSimpleEventHookClosure val = MIO.liftIO $ do
    MIO.liftIO $ B.Properties.constructObjectPropertyClosure "closure" (P.Just val)

#if defined(ENABLE_OVERLOADING)
data SimpleEventHookClosurePropertyInfo
instance AttrInfo SimpleEventHookClosurePropertyInfo where
    type AttrAllowedOps SimpleEventHookClosurePropertyInfo = '[ 'AttrConstruct, 'AttrClear]
    type AttrBaseTypeConstraint SimpleEventHookClosurePropertyInfo = IsSimpleEventHook
    type AttrSetTypeConstraint SimpleEventHookClosurePropertyInfo = (~) (GClosure ())
    type AttrTransferTypeConstraint SimpleEventHookClosurePropertyInfo = (~) (GClosure ())
    type AttrTransferType SimpleEventHookClosurePropertyInfo = GClosure ()
    type AttrGetType SimpleEventHookClosurePropertyInfo = ()
    type AttrLabel SimpleEventHookClosurePropertyInfo = "closure"
    type AttrOrigin SimpleEventHookClosurePropertyInfo = SimpleEventHook
    attrGet = undefined
    attrSet = undefined
    attrPut = undefined
    attrTransfer _ v = do
        return v
    attrConstruct = constructSimpleEventHookClosure
    attrClear = undefined
    dbgAttrInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Wp.Objects.SimpleEventHook.closure"
        , O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-wireplumber-0.5.14.2/docs/GI-Wp-Objects-SimpleEventHook.html#g:attr:closure"
        })
#endif

#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList SimpleEventHook
type instance O.AttributeList SimpleEventHook = SimpleEventHookAttributeList
type SimpleEventHookAttributeList = ('[ '("closure", SimpleEventHookClosurePropertyInfo), '("dispatcher", Wp.EventHook.EventHookDispatcherPropertyInfo), '("name", Wp.EventHook.EventHookNamePropertyInfo), '("runsAfterHooks", Wp.EventHook.EventHookRunsAfterHooksPropertyInfo), '("runsBeforeHooks", Wp.EventHook.EventHookRunsBeforeHooksPropertyInfo)] :: [(Symbol, DK.Type)])
#endif

#if defined(ENABLE_OVERLOADING)
simpleEventHookClosure :: AttrLabelProxy "closure"
simpleEventHookClosure = AttrLabelProxy

#endif

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

#endif

-- method SimpleEventHook::new
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "name"
--           , argType = TBasicType TUTF8
--           , argCType = Just "const gchar*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the name of the hook"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "before"
--           , argType = TCArray True (-1) (-1) (TBasicType TUTF8)
--           , argCType = Just "const gchar**"
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "an array of hook names that should run after this hook"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "after"
--           , argType = TCArray True (-1) (-1) (TBasicType TUTF8)
--           , argCType = Just "const gchar**"
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "an array of hook names that should run before this hook"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "closure"
--           , argType = TGClosure Nothing
--           , argCType = Just "GClosure*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "the closure to invoke when the hook is executed; the closure should accept two parameters: the event dispatcher and the event, returning nothing"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just
--               (TInterface Name { namespace = "Wp" , name = "SimpleEventHook" })
-- throws : False
-- Skip return : False

foreign import ccall "wp_simple_event_hook_new" wp_simple_event_hook_new :: 
    CString ->                              -- name : TBasicType TUTF8
    Ptr CString ->                          -- before : TCArray True (-1) (-1) (TBasicType TUTF8)
    Ptr CString ->                          -- after : TCArray True (-1) (-1) (TBasicType TUTF8)
    Ptr (GClosure ()) ->                    -- closure : TGClosure Nothing
    IO (Ptr SimpleEventHook)

-- | Constructs a new simple event hook.
simpleEventHookNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    -- ^ /@name@/: the name of the hook
    -> Maybe ([T.Text])
    -- ^ /@before@/: an array of hook names that should run after this hook
    -> Maybe ([T.Text])
    -- ^ /@after@/: an array of hook names that should run before this hook
    -> GClosure a
    -- ^ /@closure@/: the closure to invoke when the hook is executed; the closure should accept two parameters: the event dispatcher and the event, returning nothing
    -> m SimpleEventHook
    -- ^ __Returns:__ a new simple event hook
simpleEventHookNew name before after closure = liftIO $ do
    name' <- textToCString name
    maybeBefore <- case before of
        Nothing -> return FP.nullPtr
        Just jBefore -> do
            jBefore' <- packZeroTerminatedUTF8CArray jBefore
            return jBefore'
    maybeAfter <- case after of
        Nothing -> return FP.nullPtr
        Just jAfter -> do
            jAfter' <- packZeroTerminatedUTF8CArray jAfter
            return jAfter'
    closure' <- unsafeManagedPtrCastPtr closure
    result <- wp_simple_event_hook_new name' maybeBefore maybeAfter closure'
    checkUnexpectedReturnNULL "simpleEventHookNew" result
    result' <- (wrapObject SimpleEventHook) result
    touchManagedPtr closure
    freeMem name'
    mapZeroTerminatedCArray freeMem maybeBefore
    freeMem maybeBefore
    mapZeroTerminatedCArray freeMem maybeAfter
    freeMem maybeAfter
    return result'

#if defined(ENABLE_OVERLOADING)
#endif


