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

module GI.Ggit.Objects.Index
    ( 

-- * Exported types
    Index(..)                               ,
    IsIndex                                 ,
    toIndex                                 ,
    noIndex                                 ,


 -- * Methods
-- ** add #method:add#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    IndexAddMethodInfo                      ,
#endif
    indexAdd                                ,


-- ** addFile #method:addFile#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    IndexAddFileMethodInfo                  ,
#endif
    indexAddFile                            ,


-- ** addPath #method:addPath#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    IndexAddPathMethodInfo                  ,
#endif
    indexAddPath                            ,


-- ** getEntries #method:getEntries#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    IndexGetEntriesMethodInfo               ,
#endif
    indexGetEntries                         ,


-- ** getEntriesResolveUndo #method:getEntriesResolveUndo#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    IndexGetEntriesResolveUndoMethodInfo    ,
#endif
    indexGetEntriesResolveUndo              ,


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


-- ** hasConflicts #method:hasConflicts#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    IndexHasConflictsMethodInfo             ,
#endif
    indexHasConflicts                       ,


-- ** open #method:open#
    indexOpen                               ,


-- ** read #method:read#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    IndexReadMethodInfo                     ,
#endif
    indexRead                               ,


-- ** remove #method:remove#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    IndexRemoveMethodInfo                   ,
#endif
    indexRemove                             ,


-- ** write #method:write#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    IndexWriteMethodInfo                    ,
#endif
    indexWrite                              ,


-- ** writeTree #method:writeTree#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    IndexWriteTreeMethodInfo                ,
#endif
    indexWriteTree                          ,


-- ** writeTreeTo #method:writeTreeTo#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    IndexWriteTreeToMethodInfo              ,
#endif
    indexWriteTreeTo                        ,




 -- * Properties
-- ** file #attr:file#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    IndexFilePropertyInfo                   ,
#endif
    constructIndexFile                      ,
    getIndexFile                            ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    indexFile                               ,
#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.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.IndexEntries as Ggit.IndexEntries
import {-# SOURCE #-} qualified GI.Ggit.Structs.IndexEntriesResolveUndo as Ggit.IndexEntriesResolveUndo
import {-# SOURCE #-} qualified GI.Ggit.Structs.IndexEntry as Ggit.IndexEntry
import {-# SOURCE #-} qualified GI.Ggit.Structs.OId as Ggit.OId
import qualified GI.Gio.Interfaces.File as Gio.File
import qualified GI.Gio.Interfaces.Initable as Gio.Initable

newtype Index = Index (ManagedPtr Index)
foreign import ccall "ggit_index_get_type"
    c_ggit_index_get_type :: IO GType

instance GObject Index where
    gobjectType _ = c_ggit_index_get_type
    

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

toIndex :: (MonadIO m, IsIndex o) => o -> m Index
toIndex = liftIO . unsafeCastTo Index

noIndex :: Maybe Index
noIndex = Nothing

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type family ResolveIndexMethod (t :: Symbol) (o :: *) :: * where
    ResolveIndexMethod "add" o = IndexAddMethodInfo
    ResolveIndexMethod "addFile" o = IndexAddFileMethodInfo
    ResolveIndexMethod "addPath" o = IndexAddPathMethodInfo
    ResolveIndexMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveIndexMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveIndexMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveIndexMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveIndexMethod "hasConflicts" o = IndexHasConflictsMethodInfo
    ResolveIndexMethod "init" o = Gio.Initable.InitableInitMethodInfo
    ResolveIndexMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveIndexMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveIndexMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveIndexMethod "read" o = IndexReadMethodInfo
    ResolveIndexMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveIndexMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveIndexMethod "remove" o = IndexRemoveMethodInfo
    ResolveIndexMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveIndexMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveIndexMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveIndexMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveIndexMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveIndexMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveIndexMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveIndexMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveIndexMethod "write" o = IndexWriteMethodInfo
    ResolveIndexMethod "writeTree" o = IndexWriteTreeMethodInfo
    ResolveIndexMethod "writeTreeTo" o = IndexWriteTreeToMethodInfo
    ResolveIndexMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveIndexMethod "getEntries" o = IndexGetEntriesMethodInfo
    ResolveIndexMethod "getEntriesResolveUndo" o = IndexGetEntriesResolveUndoMethodInfo
    ResolveIndexMethod "getOwner" o = IndexGetOwnerMethodInfo
    ResolveIndexMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveIndexMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveIndexMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveIndexMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveIndexMethod l o = O.MethodResolutionFailed l o

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

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveIndexMethod t Index, O.MethodInfo info Index p) => O.IsLabel t (Index -> 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 "file"
   -- Type: TInterface (Name {namespace = "Gio", name = "File"})
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Nothing,Nothing)

getIndexFile :: (MonadIO m, IsIndex o) => o -> m (Maybe Gio.File.File)
getIndexFile obj = liftIO $ getObjectPropertyObject obj "file" Gio.File.File

constructIndexFile :: (IsIndex o, Gio.File.IsFile a) => a -> IO (GValueConstruct o)
constructIndexFile val = constructObjectPropertyObject "file" (Just val)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data IndexFilePropertyInfo
instance AttrInfo IndexFilePropertyInfo where
    type AttrAllowedOps IndexFilePropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint IndexFilePropertyInfo = Gio.File.IsFile
    type AttrBaseTypeConstraint IndexFilePropertyInfo = IsIndex
    type AttrGetType IndexFilePropertyInfo = (Maybe Gio.File.File)
    type AttrLabel IndexFilePropertyInfo = "file"
    type AttrOrigin IndexFilePropertyInfo = Index
    attrGet _ = getIndexFile
    attrSet _ = undefined
    attrConstruct _ = constructIndexFile
    attrClear _ = undefined
#endif

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

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
indexFile :: AttrLabelProxy "file"
indexFile = AttrLabelProxy

#endif

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

#endif

-- method Index::add
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "idx", argType = TInterface (Name {namespace = "Ggit", name = "Index"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitIndex.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "entry", argType = TInterface (Name {namespace = "Ggit", name = "IndexEntry"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitIndexEntry.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "ggit_index_add" ggit_index_add :: 
    Ptr Index ->                            -- idx : TInterface (Name {namespace = "Ggit", name = "Index"})
    Ptr Ggit.IndexEntry.IndexEntry ->       -- entry : TInterface (Name {namespace = "Ggit", name = "IndexEntry"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Add a file to the index.
-}
indexAdd ::
    (B.CallStack.HasCallStack, MonadIO m, IsIndex a) =>
    a
    {- ^ /@idx@/: a 'GI.Ggit.Objects.Index.Index'. -}
    -> Ggit.IndexEntry.IndexEntry
    {- ^ /@entry@/: a 'GI.Ggit.Structs.IndexEntry.IndexEntry'. -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
indexAdd idx entry = liftIO $ do
    idx' <- unsafeManagedPtrCastPtr idx
    entry' <- unsafeManagedPtrGetPtr entry
    onException (do
        _ <- propagateGError $ ggit_index_add idx' entry'
        touchManagedPtr idx
        touchManagedPtr entry
        return ()
     ) (do
        return ()
     )

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data IndexAddMethodInfo
instance (signature ~ (Ggit.IndexEntry.IndexEntry -> m ()), MonadIO m, IsIndex a) => O.MethodInfo IndexAddMethodInfo a signature where
    overloadedMethod _ = indexAdd

#endif

-- method Index::add_file
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "idx", argType = TInterface (Name {namespace = "Ggit", name = "Index"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitIndex.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "file", argType = TInterface (Name {namespace = "Gio", name = "File"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "file to add.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "ggit_index_add_file" ggit_index_add_file :: 
    Ptr Index ->                            -- idx : TInterface (Name {namespace = "Ggit", name = "Index"})
    Ptr Gio.File.File ->                    -- file : TInterface (Name {namespace = "Gio", name = "File"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Add a file to the index. The specified file must be in the working directory
and must exist and be readable.
-}
indexAddFile ::
    (B.CallStack.HasCallStack, MonadIO m, IsIndex a, Gio.File.IsFile b) =>
    a
    {- ^ /@idx@/: a 'GI.Ggit.Objects.Index.Index'. -}
    -> b
    {- ^ /@file@/: file to add. -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
indexAddFile idx file = liftIO $ do
    idx' <- unsafeManagedPtrCastPtr idx
    file' <- unsafeManagedPtrCastPtr file
    onException (do
        _ <- propagateGError $ ggit_index_add_file idx' file'
        touchManagedPtr idx
        touchManagedPtr file
        return ()
     ) (do
        return ()
     )

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data IndexAddFileMethodInfo
instance (signature ~ (b -> m ()), MonadIO m, IsIndex a, Gio.File.IsFile b) => O.MethodInfo IndexAddFileMethodInfo a signature where
    overloadedMethod _ = indexAddFile

#endif

-- method Index::add_path
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "idx", argType = TInterface (Name {namespace = "Ggit", name = "Index"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitIndex.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "path", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "path to the file to add.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "ggit_index_add_path" ggit_index_add_path :: 
    Ptr Index ->                            -- idx : TInterface (Name {namespace = "Ggit", name = "Index"})
    CString ->                              -- path : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Add a file to the index by path. You can specify both relative paths
(to the working directory) and absolute paths. Absolute paths however must
reside in the working directory. The specified path must exist and must be
readable.
-}
indexAddPath ::
    (B.CallStack.HasCallStack, MonadIO m, IsIndex a) =>
    a
    {- ^ /@idx@/: a 'GI.Ggit.Objects.Index.Index'. -}
    -> T.Text
    {- ^ /@path@/: path to the file to add. -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
indexAddPath idx path = liftIO $ do
    idx' <- unsafeManagedPtrCastPtr idx
    path' <- textToCString path
    onException (do
        _ <- propagateGError $ ggit_index_add_path idx' path'
        touchManagedPtr idx
        freeMem path'
        return ()
     ) (do
        freeMem path'
     )

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data IndexAddPathMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m, IsIndex a) => O.MethodInfo IndexAddPathMethodInfo a signature where
    overloadedMethod _ = indexAddPath

#endif

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

foreign import ccall "ggit_index_get_entries" ggit_index_get_entries :: 
    Ptr Index ->                            -- idx : TInterface (Name {namespace = "Ggit", name = "Index"})
    IO (Ptr Ggit.IndexEntries.IndexEntries)

{- |
Get the index entries enumerator.
-}
indexGetEntries ::
    (B.CallStack.HasCallStack, MonadIO m, IsIndex a) =>
    a
    {- ^ /@idx@/: a 'GI.Ggit.Objects.Index.Index'. -}
    -> m Ggit.IndexEntries.IndexEntries
    {- ^ __Returns:__ a 'GI.Ggit.Structs.IndexEntries.IndexEntries'. -}
indexGetEntries idx = liftIO $ do
    idx' <- unsafeManagedPtrCastPtr idx
    result <- ggit_index_get_entries idx'
    checkUnexpectedReturnNULL "indexGetEntries" result
    result' <- (wrapBoxed Ggit.IndexEntries.IndexEntries) result
    touchManagedPtr idx
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data IndexGetEntriesMethodInfo
instance (signature ~ (m Ggit.IndexEntries.IndexEntries), MonadIO m, IsIndex a) => O.MethodInfo IndexGetEntriesMethodInfo a signature where
    overloadedMethod _ = indexGetEntries

#endif

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

foreign import ccall "ggit_index_get_entries_resolve_undo" ggit_index_get_entries_resolve_undo :: 
    Ptr Index ->                            -- idx : TInterface (Name {namespace = "Ggit", name = "Index"})
    IO (Ptr Ggit.IndexEntriesResolveUndo.IndexEntriesResolveUndo)

{- |
Get the resolve undo entries enumerator.
-}
indexGetEntriesResolveUndo ::
    (B.CallStack.HasCallStack, MonadIO m, IsIndex a) =>
    a
    {- ^ /@idx@/: a 'GI.Ggit.Objects.Index.Index'. -}
    -> m Ggit.IndexEntriesResolveUndo.IndexEntriesResolveUndo
    {- ^ __Returns:__ a 'GI.Ggit.Structs.IndexEntriesResolveUndo.IndexEntriesResolveUndo'. -}
indexGetEntriesResolveUndo idx = liftIO $ do
    idx' <- unsafeManagedPtrCastPtr idx
    result <- ggit_index_get_entries_resolve_undo idx'
    checkUnexpectedReturnNULL "indexGetEntriesResolveUndo" result
    result' <- (wrapBoxed Ggit.IndexEntriesResolveUndo.IndexEntriesResolveUndo) result
    touchManagedPtr idx
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data IndexGetEntriesResolveUndoMethodInfo
instance (signature ~ (m Ggit.IndexEntriesResolveUndo.IndexEntriesResolveUndo), MonadIO m, IsIndex a) => O.MethodInfo IndexGetEntriesResolveUndoMethodInfo a signature where
    overloadedMethod _ = indexGetEntriesResolveUndo

#endif

-- method Index::get_owner
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "idx", argType = TInterface (Name {namespace = "Ggit", name = "Index"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitIndex.", 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_index_get_owner" ggit_index_get_owner :: 
    Ptr Index ->                            -- idx : TInterface (Name {namespace = "Ggit", name = "Index"})
    IO (Ptr Ggit.Repository.Repository)

{- |
Get the 'GI.Ggit.Objects.Repository.Repository' that owns the index.
-}
indexGetOwner ::
    (B.CallStack.HasCallStack, MonadIO m, IsIndex a) =>
    a
    {- ^ /@idx@/: a 'GI.Ggit.Objects.Index.Index'. -}
    -> m Ggit.Repository.Repository
    {- ^ __Returns:__ the 'GI.Ggit.Objects.Repository.Repository' that owns this index. -}
indexGetOwner idx = liftIO $ do
    idx' <- unsafeManagedPtrCastPtr idx
    result <- ggit_index_get_owner idx'
    checkUnexpectedReturnNULL "indexGetOwner" result
    result' <- (wrapObject Ggit.Repository.Repository) result
    touchManagedPtr idx
    return result'

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

#endif

-- method Index::has_conflicts
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "idx", argType = TInterface (Name {namespace = "Ggit", name = "Index"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitIndex.", 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 "ggit_index_has_conflicts" ggit_index_has_conflicts :: 
    Ptr Index ->                            -- idx : TInterface (Name {namespace = "Ggit", name = "Index"})
    IO CInt

{- |
Get whether the index has any conflicts.
-}
indexHasConflicts ::
    (B.CallStack.HasCallStack, MonadIO m, IsIndex a) =>
    a
    {- ^ /@idx@/: a 'GI.Ggit.Objects.Index.Index'. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the index has any conflicts, 'False' otherwise. -}
indexHasConflicts idx = liftIO $ do
    idx' <- unsafeManagedPtrCastPtr idx
    result <- ggit_index_has_conflicts idx'
    let result' = (/= 0) result
    touchManagedPtr idx
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data IndexHasConflictsMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsIndex a) => O.MethodInfo IndexHasConflictsMethodInfo a signature where
    overloadedMethod _ = indexHasConflicts

#endif

-- method Index::read
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "idx", argType = TInterface (Name {namespace = "Ggit", name = "Index"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitIndex.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "force", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "force read even if there are in-memory changes.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "ggit_index_read" ggit_index_read :: 
    Ptr Index ->                            -- idx : TInterface (Name {namespace = "Ggit", name = "Index"})
    CInt ->                                 -- force : TBasicType TBoolean
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Update the contents of an existing index object in memory by reading from
the hard disk.

If /@force@/ is true, this performs a \"hard\" read that discards in-memory
changes and always reloads the on-disk index data. If there is no on-disk
version, the index will be cleared.

If /@force@/ is false, this does a \"soft\" read that reloads the index data from
disk only if it has changed since the last time it was loaded. Purely
in-memory index data will be untouched. Be aware: if there are changes on
disk, unwritten in-memory changes are discarded.
-}
indexRead ::
    (B.CallStack.HasCallStack, MonadIO m, IsIndex a) =>
    a
    {- ^ /@idx@/: a 'GI.Ggit.Objects.Index.Index'. -}
    -> Bool
    {- ^ /@force@/: force read even if there are in-memory changes. -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
indexRead idx force = liftIO $ do
    idx' <- unsafeManagedPtrCastPtr idx
    let force' = (fromIntegral . fromEnum) force
    onException (do
        _ <- propagateGError $ ggit_index_read idx' force'
        touchManagedPtr idx
        return ()
     ) (do
        return ()
     )

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data IndexReadMethodInfo
instance (signature ~ (Bool -> m ()), MonadIO m, IsIndex a) => O.MethodInfo IndexReadMethodInfo a signature where
    overloadedMethod _ = indexRead

#endif

-- method Index::remove
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "idx", argType = TInterface (Name {namespace = "Ggit", name = "Index"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitIndex.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "file", argType = TInterface (Name {namespace = "Gio", name = "File"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the file to search.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "stage", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the stage to search.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "ggit_index_remove" ggit_index_remove :: 
    Ptr Index ->                            -- idx : TInterface (Name {namespace = "Ggit", name = "Index"})
    Ptr Gio.File.File ->                    -- file : TInterface (Name {namespace = "Gio", name = "File"})
    Int32 ->                                -- stage : TBasicType TInt
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Remove a file from the index (specified by position).
-}
indexRemove ::
    (B.CallStack.HasCallStack, MonadIO m, IsIndex a, Gio.File.IsFile b) =>
    a
    {- ^ /@idx@/: a 'GI.Ggit.Objects.Index.Index'. -}
    -> b
    {- ^ /@file@/: the file to search. -}
    -> Int32
    {- ^ /@stage@/: the stage to search. -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
indexRemove idx file stage = liftIO $ do
    idx' <- unsafeManagedPtrCastPtr idx
    file' <- unsafeManagedPtrCastPtr file
    onException (do
        _ <- propagateGError $ ggit_index_remove idx' file' stage
        touchManagedPtr idx
        touchManagedPtr file
        return ()
     ) (do
        return ()
     )

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data IndexRemoveMethodInfo
instance (signature ~ (b -> Int32 -> m ()), MonadIO m, IsIndex a, Gio.File.IsFile b) => O.MethodInfo IndexRemoveMethodInfo a signature where
    overloadedMethod _ = indexRemove

#endif

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

foreign import ccall "ggit_index_write" ggit_index_write :: 
    Ptr Index ->                            -- idx : TInterface (Name {namespace = "Ggit", name = "Index"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Write an existing index object from memory back to disk using an atomic file
lock.
-}
indexWrite ::
    (B.CallStack.HasCallStack, MonadIO m, IsIndex a) =>
    a
    {- ^ /@idx@/: a 'GI.Ggit.Objects.Index.Index'. -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
indexWrite idx = liftIO $ do
    idx' <- unsafeManagedPtrCastPtr idx
    onException (do
        _ <- propagateGError $ ggit_index_write idx'
        touchManagedPtr idx
        return ()
     ) (do
        return ()
     )

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data IndexWriteMethodInfo
instance (signature ~ (m ()), MonadIO m, IsIndex a) => O.MethodInfo IndexWriteMethodInfo a signature where
    overloadedMethod _ = indexWrite

#endif

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

foreign import ccall "ggit_index_write_tree" ggit_index_write_tree :: 
    Ptr Index ->                            -- idx : TInterface (Name {namespace = "Ggit", name = "Index"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Ggit.OId.OId)

{- |
Write a new tree object to disk containing a representation of the current
state of the index. The index must be associated to an existing repository
and must not contain any files in conflict. You can use the resulting tree
to for instance create a commit.
-}
indexWriteTree ::
    (B.CallStack.HasCallStack, MonadIO m, IsIndex a) =>
    a
    {- ^ /@idx@/: a 'GI.Ggit.Objects.Index.Index'. -}
    -> m Ggit.OId.OId
    {- ^ __Returns:__ a 'GI.Ggit.Structs.OId.OId' or 'Nothing' in case of an error. /(Can throw 'Data.GI.Base.GError.GError')/ -}
indexWriteTree idx = liftIO $ do
    idx' <- unsafeManagedPtrCastPtr idx
    onException (do
        result <- propagateGError $ ggit_index_write_tree idx'
        checkUnexpectedReturnNULL "indexWriteTree" result
        result' <- (wrapBoxed Ggit.OId.OId) result
        touchManagedPtr idx
        return result'
     ) (do
        return ()
     )

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

#endif

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

foreign import ccall "ggit_index_write_tree_to" ggit_index_write_tree_to :: 
    Ptr Index ->                            -- idx : TInterface (Name {namespace = "Ggit", name = "Index"})
    Ptr Ggit.Repository.Repository ->       -- repository : TInterface (Name {namespace = "Ggit", name = "Repository"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Ggit.OId.OId)

{- |
Write a new tree object to /@repository@/ containing a representation of the current
state of the index. The index must not contain any files in conflict. You can use
the resulting tree to for instance create a commit.
-}
indexWriteTreeTo ::
    (B.CallStack.HasCallStack, MonadIO m, IsIndex a, Ggit.Repository.IsRepository b) =>
    a
    {- ^ /@idx@/: a 'GI.Ggit.Objects.Index.Index'. -}
    -> b
    {- ^ /@repository@/: a 'GI.Ggit.Objects.Repository.Repository'. -}
    -> m Ggit.OId.OId
    {- ^ __Returns:__ a 'GI.Ggit.Structs.OId.OId' or 'Nothing' in case of an error. /(Can throw 'Data.GI.Base.GError.GError')/ -}
indexWriteTreeTo idx repository = liftIO $ do
    idx' <- unsafeManagedPtrCastPtr idx
    repository' <- unsafeManagedPtrCastPtr repository
    onException (do
        result <- propagateGError $ ggit_index_write_tree_to idx' repository'
        checkUnexpectedReturnNULL "indexWriteTreeTo" result
        result' <- (wrapBoxed Ggit.OId.OId) result
        touchManagedPtr idx
        touchManagedPtr repository
        return result'
     ) (do
        return ()
     )

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data IndexWriteTreeToMethodInfo
instance (signature ~ (b -> m Ggit.OId.OId), MonadIO m, IsIndex a, Ggit.Repository.IsRepository b) => O.MethodInfo IndexWriteTreeToMethodInfo a signature where
    overloadedMethod _ = indexWriteTreeTo

#endif

-- method Index::open
-- method type : MemberFunction
-- Args : [Arg {argCName = "file", argType = TInterface (Name {namespace = "Gio", name = "File"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GFile.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "Index"}))
-- throws : True
-- Skip return : False

foreign import ccall "ggit_index_open" ggit_index_open :: 
    Ptr Gio.File.File ->                    -- file : TInterface (Name {namespace = "Gio", name = "File"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Index)

{- |
Create a new bare Git index object as a memory representation of the Git
index file in /@file@/, without a repository to back it.
-}
indexOpen ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.File.IsFile a) =>
    a
    {- ^ /@file@/: a 'GI.Gio.Interfaces.File.File'. -}
    -> m Index
    {- ^ __Returns:__ a 'GI.Ggit.Objects.Index.Index' or 'Nothing' if an error occurred. /(Can throw 'Data.GI.Base.GError.GError')/ -}
indexOpen file = liftIO $ do
    file' <- unsafeManagedPtrCastPtr file
    onException (do
        result <- propagateGError $ ggit_index_open file'
        checkUnexpectedReturnNULL "indexOpen" result
        result' <- (wrapObject Index) result
        touchManagedPtr file
        return result'
     ) (do
        return ()
     )

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