{- |
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 native object.
-}

module GI.Ggit.Objects.Native
    ( 

-- * Exported types
    Native(..)                              ,
    IsNative                                ,
    toNative                                ,
    noNative                                ,


 -- * Properties
-- ** native #attr:native#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    NativeNativePropertyInfo                ,
#endif
    constructNativeNative                   ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    nativeNative                            ,
#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.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.ObjectFactoryBase as Ggit.ObjectFactoryBase

newtype Native = Native (ManagedPtr Native)
foreign import ccall "ggit_native_get_type"
    c_ggit_native_get_type :: IO GType

instance GObject Native where
    gobjectType _ = c_ggit_native_get_type
    

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

toNative :: (MonadIO m, IsNative o) => o -> m Native
toNative = liftIO . unsafeCastTo Native

noNative :: Maybe Native
noNative = Nothing

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

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

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveNativeMethod t Native, O.MethodInfo info Native p) => O.IsLabel t (Native -> 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

-- VVV Prop "native"
   -- Type: TBasicType TPtr
   -- Flags: [PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Nothing,Nothing)

constructNativeNative :: (IsNative o) => Ptr () -> IO (GValueConstruct o)
constructNativeNative val = constructObjectPropertyPtr "native" val

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data NativeNativePropertyInfo
instance AttrInfo NativeNativePropertyInfo where
    type AttrAllowedOps NativeNativePropertyInfo = '[ 'AttrConstruct]
    type AttrSetTypeConstraint NativeNativePropertyInfo = (~) (Ptr ())
    type AttrBaseTypeConstraint NativeNativePropertyInfo = IsNative
    type AttrGetType NativeNativePropertyInfo = ()
    type AttrLabel NativeNativePropertyInfo = "native"
    type AttrOrigin NativeNativePropertyInfo = Native
    attrGet _ = undefined
    attrSet _ = undefined
    attrConstruct _ = constructNativeNative
    attrClear _ = undefined
#endif

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

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
nativeNative :: AttrLabelProxy "native"
nativeNative = AttrLabelProxy

#endif

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

#endif