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

Represents a generic object in a repository.
-}

module GI.Ggit.Objects.Object
    ( 

-- * Exported types
    Object(..)                              ,
    IsObject                                ,
    toObject                                ,
    noObject                                ,


 -- * Methods
-- ** getId #method:getId#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    ObjectGetIdMethodInfo                   ,
#endif
    objectGetId                             ,


-- ** getOwner #method:getOwner#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    ObjectGetOwnerMethodInfo                ,
#endif
    objectGetOwner                          ,




    ) 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.Ggit.Objects.Native as Ggit.Native
import {-# SOURCE #-} qualified GI.Ggit.Objects.ObjectFactoryBase as Ggit.ObjectFactoryBase
import {-# SOURCE #-} qualified GI.Ggit.Objects.Repository as Ggit.Repository
import {-# SOURCE #-} qualified GI.Ggit.Structs.OId as Ggit.OId

newtype Object = Object (ManagedPtr Object)
foreign import ccall "ggit_object_get_type"
    c_ggit_object_get_type :: IO GType

instance GObject Object where
    gobjectType _ = c_ggit_object_get_type
    

class GObject o => IsObject o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError Object a) =>
    IsObject a
#endif
instance IsObject Object
instance Ggit.Native.IsNative Object
instance Ggit.ObjectFactoryBase.IsObjectFactoryBase Object
instance GObject.Object.IsObject Object

toObject :: (MonadIO m, IsObject o) => o -> m Object
toObject = liftIO . unsafeCastTo Object

noObject :: Maybe Object
noObject = Nothing

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type family ResolveObjectMethod (t :: Symbol) (o :: *) :: * where
    ResolveObjectMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveObjectMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveObjectMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveObjectMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveObjectMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveObjectMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveObjectMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveObjectMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveObjectMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveObjectMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveObjectMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveObjectMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveObjectMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveObjectMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveObjectMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveObjectMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveObjectMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveObjectMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveObjectMethod "getId" o = ObjectGetIdMethodInfo
    ResolveObjectMethod "getOwner" o = ObjectGetOwnerMethodInfo
    ResolveObjectMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveObjectMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveObjectMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveObjectMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveObjectMethod l o = O.MethodResolutionFailed l o

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

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

#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
instance O.HasAttributeList Object
type instance O.AttributeList Object = ObjectAttributeList
type ObjectAttributeList = ('[ '("native", Ggit.Native.NativeNativePropertyInfo)] :: [(Symbol, *)])
#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type instance O.SignalList Object = ObjectSignalList
type ObjectSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method Object::get_id
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "object", argType = TInterface (Name {namespace = "Ggit", name = "Object"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitObject.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "OId"}))
-- throws : False
-- Skip return : False

foreign import ccall "ggit_object_get_id" ggit_object_get_id :: 
    Ptr Object ->                           -- object : TInterface (Name {namespace = "Ggit", name = "Object"})
    IO (Ptr Ggit.OId.OId)

{- |
Gets the 'GI.Ggit.Structs.OId.OId' of /@object@/.
-}
objectGetId ::
    (B.CallStack.HasCallStack, MonadIO m, IsObject a) =>
    a
    {- ^ /@object@/: a 'GI.Ggit.Objects.Object.Object'. -}
    -> m Ggit.OId.OId
    {- ^ __Returns:__ the 'GI.Ggit.Structs.OId.OId' of the object. -}
objectGetId object = liftIO $ do
    object' <- unsafeManagedPtrCastPtr object
    result <- ggit_object_get_id object'
    checkUnexpectedReturnNULL "objectGetId" result
    result' <- (wrapBoxed Ggit.OId.OId) result
    touchManagedPtr object
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data ObjectGetIdMethodInfo
instance (signature ~ (m Ggit.OId.OId), MonadIO m, IsObject a) => O.MethodInfo ObjectGetIdMethodInfo a signature where
    overloadedMethod _ = objectGetId

#endif

-- method Object::get_owner
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "object", argType = TInterface (Name {namespace = "Ggit", name = "Object"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitObject.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "Repository"}))
-- throws : False
-- Skip return : False

foreign import ccall "ggit_object_get_owner" ggit_object_get_owner :: 
    Ptr Object ->                           -- object : TInterface (Name {namespace = "Ggit", name = "Object"})
    IO (Ptr Ggit.Repository.Repository)

{- |
Gets the 'GI.Ggit.Objects.Repository.Repository' that owns /@object@/.
-}
objectGetOwner ::
    (B.CallStack.HasCallStack, MonadIO m, IsObject a) =>
    a
    {- ^ /@object@/: a 'GI.Ggit.Objects.Object.Object'. -}
    -> m Ggit.Repository.Repository
    {- ^ __Returns:__ the 'GI.Ggit.Objects.Repository.Repository' that owns this object.
The returned value must be free\'d calling 'GI.GObject.Objects.Object.objectUnref'. -}
objectGetOwner object = liftIO $ do
    object' <- unsafeManagedPtrCastPtr object
    result <- ggit_object_get_owner object'
    checkUnexpectedReturnNULL "objectGetOwner" result
    result' <- (wrapObject Ggit.Repository.Repository) result
    touchManagedPtr object
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data ObjectGetOwnerMethodInfo
instance (signature ~ (m Ggit.Repository.Repository), MonadIO m, IsObject a) => O.MethodInfo ObjectGetOwnerMethodInfo a signature where
    overloadedMethod _ = objectGetOwner

#endif