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

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

module GI.Ggit.Structs.IndexEntries
    (

-- * Exported types
    IndexEntries(..)                        ,
    noIndexEntries                          ,


 -- * Methods
-- ** getByIndex #method:getByIndex#

#if ENABLE_OVERLOADING
    IndexEntriesGetByIndexMethodInfo        ,
#endif
    indexEntriesGetByIndex                  ,


-- ** getByPath #method:getByPath#

#if ENABLE_OVERLOADING
    IndexEntriesGetByPathMethodInfo         ,
#endif
    indexEntriesGetByPath                   ,


-- ** ref #method:ref#

#if ENABLE_OVERLOADING
    IndexEntriesRefMethodInfo               ,
#endif
    indexEntriesRef                         ,


-- ** size #method:size#

#if ENABLE_OVERLOADING
    IndexEntriesSizeMethodInfo              ,
#endif
    indexEntriesSize                        ,


-- ** unref #method:unref#

#if ENABLE_OVERLOADING
    IndexEntriesUnrefMethodInfo             ,
#endif
    indexEntriesUnref                       ,




    ) 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.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.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP

import {-# SOURCE #-} qualified GI.Ggit.Structs.IndexEntry as Ggit.IndexEntry
import qualified GI.Gio.Interfaces.File as Gio.File

-- | Memory-managed wrapper type.
newtype IndexEntries = IndexEntries (ManagedPtr IndexEntries)
foreign import ccall "ggit_index_entries_get_type" c_ggit_index_entries_get_type ::
    IO GType

instance BoxedObject IndexEntries where
    boxedType _ = c_ggit_index_entries_get_type

-- | A convenience alias for `Nothing` :: `Maybe` `IndexEntries`.
noIndexEntries :: Maybe IndexEntries
noIndexEntries = Nothing


#if ENABLE_OVERLOADING
instance O.HasAttributeList IndexEntries
type instance O.AttributeList IndexEntries = IndexEntriesAttributeList
type IndexEntriesAttributeList = ('[ ] :: [(Symbol, *)])
#endif

-- method IndexEntries::get_by_index
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "entries", argType = TInterface (Name {namespace = "Ggit", name = "IndexEntries"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitIndexEntries.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "idx", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the index of the entry.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "IndexEntry"}))
-- throws : False
-- Skip return : False

foreign import ccall "ggit_index_entries_get_by_index" ggit_index_entries_get_by_index ::
    Ptr IndexEntries ->                     -- entries : TInterface (Name {namespace = "Ggit", name = "IndexEntries"})
    Word64 ->                               -- idx : TBasicType TUInt64
    IO (Ptr Ggit.IndexEntry.IndexEntry)

{- |
Get a 'GI.Ggit.Structs.IndexEntry.IndexEntry' by index. Note that the returned 'GI.Ggit.Structs.IndexEntry.IndexEntry' is
_only_ valid as long as:

1) The associated index has been closed
2) The entry has not been removed (see 'GI.Ggit.Objects.Index.indexRemove')
3) The index has not been refreshed (see 'GI.Ggit.Objects.Index.indexRead')

Changes to the 'GI.Ggit.Structs.IndexEntry.IndexEntry' will be reflected in the index once written
back to disk using 'GI.Ggit.Objects.Index.indexWrite'.
-}
indexEntriesGetByIndex ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    IndexEntries
    {- ^ /@entries@/: a 'GI.Ggit.Structs.IndexEntries.IndexEntries'. -}
    -> Word64
    {- ^ /@idx@/: the index of the entry. -}
    -> m (Maybe Ggit.IndexEntry.IndexEntry)
    {- ^ __Returns:__ a 'GI.Ggit.Structs.IndexEntry.IndexEntry' or 'Nothing' if out of bounds. -}
indexEntriesGetByIndex entries idx = liftIO $ do
    entries' <- unsafeManagedPtrGetPtr entries
    result <- ggit_index_entries_get_by_index entries' idx
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed Ggit.IndexEntry.IndexEntry) result'
        return result''
    touchManagedPtr entries
    return maybeResult

#if ENABLE_OVERLOADING
data IndexEntriesGetByIndexMethodInfo
instance (signature ~ (Word64 -> m (Maybe Ggit.IndexEntry.IndexEntry)), MonadIO m) => O.MethodInfo IndexEntriesGetByIndexMethodInfo IndexEntries signature where
    overloadedMethod _ = indexEntriesGetByIndex

#endif

-- method IndexEntries::get_by_path
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "entries", argType = TInterface (Name {namespace = "Ggit", name = "IndexEntries"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitIndexEntries.", 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 path 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 "stage to search.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "IndexEntry"}))
-- throws : False
-- Skip return : False

foreign import ccall "ggit_index_entries_get_by_path" ggit_index_entries_get_by_path ::
    Ptr IndexEntries ->                     -- entries : TInterface (Name {namespace = "Ggit", name = "IndexEntries"})
    Ptr Gio.File.File ->                    -- file : TInterface (Name {namespace = "Gio", name = "File"})
    Int32 ->                                -- stage : TBasicType TInt
    IO (Ptr Ggit.IndexEntry.IndexEntry)

{- |
Get a 'GI.Ggit.Structs.IndexEntry.IndexEntry' by index. Note that the returned 'GI.Ggit.Structs.IndexEntry.IndexEntry' is
_only_ valid as long as:

1) The associated index has not been closed
2) The entry has not been removed (see 'GI.Ggit.Objects.Index.indexRemove')
3) The index has not been refreshed (see 'GI.Ggit.Objects.Index.indexRead')

Changes to the 'GI.Ggit.Structs.IndexEntry.IndexEntry' will be reflected in the index once written
back to disk using 'GI.Ggit.Objects.Index.indexWrite'.

/@stage@/ indicates the stage to search the file for. Stages are used in the
index when merge conflicts occur, such that multiple versions of the same
file can be represented in the index. Stage 0 is associated with the working
tree, while stages 1 to 3 are associated with the various versions of the
file in a merge conflict. The special value -1 can be used to match the first
file encountered in any stage.
-}
indexEntriesGetByPath ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.File.IsFile a) =>
    IndexEntries
    {- ^ /@entries@/: a 'GI.Ggit.Structs.IndexEntries.IndexEntries'. -}
    -> a
    {- ^ /@file@/: the path to search. -}
    -> Int32
    {- ^ /@stage@/: stage to search. -}
    -> m (Maybe Ggit.IndexEntry.IndexEntry)
    {- ^ __Returns:__ a 'GI.Ggit.Structs.IndexEntry.IndexEntry' or 'Nothing' if it was not found. -}
indexEntriesGetByPath entries file stage = liftIO $ do
    entries' <- unsafeManagedPtrGetPtr entries
    file' <- unsafeManagedPtrCastPtr file
    result <- ggit_index_entries_get_by_path entries' file' stage
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed Ggit.IndexEntry.IndexEntry) result'
        return result''
    touchManagedPtr entries
    touchManagedPtr file
    return maybeResult

#if ENABLE_OVERLOADING
data IndexEntriesGetByPathMethodInfo
instance (signature ~ (a -> Int32 -> m (Maybe Ggit.IndexEntry.IndexEntry)), MonadIO m, Gio.File.IsFile a) => O.MethodInfo IndexEntriesGetByPathMethodInfo IndexEntries signature where
    overloadedMethod _ = indexEntriesGetByPath

#endif

-- method IndexEntries::ref
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "entries", argType = TInterface (Name {namespace = "Ggit", name = "IndexEntries"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitIndexEntries.", 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_entries_ref" ggit_index_entries_ref ::
    Ptr IndexEntries ->                     -- entries : TInterface (Name {namespace = "Ggit", name = "IndexEntries"})
    IO (Ptr IndexEntries)

{- |
Atomically increments the reference count of /@entries@/ by one.
This function is MT-safe and may be called from any thread.
-}
indexEntriesRef ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    IndexEntries
    {- ^ /@entries@/: a 'GI.Ggit.Structs.IndexEntries.IndexEntries'. -}
    -> m (Maybe IndexEntries)
    {- ^ __Returns:__ a 'GI.Ggit.Structs.IndexEntries.IndexEntries' or 'Nothing'. -}
indexEntriesRef entries = liftIO $ do
    entries' <- unsafeManagedPtrGetPtr entries
    result <- ggit_index_entries_ref entries'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (newBoxed IndexEntries) result'
        return result''
    touchManagedPtr entries
    return maybeResult

#if ENABLE_OVERLOADING
data IndexEntriesRefMethodInfo
instance (signature ~ (m (Maybe IndexEntries)), MonadIO m) => O.MethodInfo IndexEntriesRefMethodInfo IndexEntries signature where
    overloadedMethod _ = indexEntriesRef

#endif

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

foreign import ccall "ggit_index_entries_size" ggit_index_entries_size ::
    Ptr IndexEntries ->                     -- entries : TInterface (Name {namespace = "Ggit", name = "IndexEntries"})
    IO Word32

{- |
Get the number of 'GI.Ggit.Structs.IndexEntry.IndexEntry' entries.
-}
indexEntriesSize ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    IndexEntries
    {- ^ /@entries@/: a 'GI.Ggit.Structs.IndexEntries.IndexEntries'. -}
    -> m Word32
    {- ^ __Returns:__ the number of entries. -}
indexEntriesSize entries = liftIO $ do
    entries' <- unsafeManagedPtrGetPtr entries
    result <- ggit_index_entries_size entries'
    touchManagedPtr entries
    return result

#if ENABLE_OVERLOADING
data IndexEntriesSizeMethodInfo
instance (signature ~ (m Word32), MonadIO m) => O.MethodInfo IndexEntriesSizeMethodInfo IndexEntries signature where
    overloadedMethod _ = indexEntriesSize

#endif

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

foreign import ccall "ggit_index_entries_unref" ggit_index_entries_unref ::
    Ptr IndexEntries ->                     -- entries : TInterface (Name {namespace = "Ggit", name = "IndexEntries"})
    IO ()

{- |
Atomically decrements the reference count of /@entries@/ by one.
If the reference count drops to 0, /@entries@/ is freed.
-}
indexEntriesUnref ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    IndexEntries
    {- ^ /@entries@/: a 'GI.Ggit.Structs.IndexEntries.IndexEntries'. -}
    -> m ()
indexEntriesUnref entries = liftIO $ do
    entries' <- unsafeManagedPtrGetPtr entries
    ggit_index_entries_unref entries'
    touchManagedPtr entries
    return ()

#if ENABLE_OVERLOADING
data IndexEntriesUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo IndexEntriesUnrefMethodInfo IndexEntries signature where
    overloadedMethod _ = indexEntriesUnref

#endif

#if ENABLE_OVERLOADING
type family ResolveIndexEntriesMethod (t :: Symbol) (o :: *) :: * where
    ResolveIndexEntriesMethod "ref" o = IndexEntriesRefMethodInfo
    ResolveIndexEntriesMethod "size" o = IndexEntriesSizeMethodInfo
    ResolveIndexEntriesMethod "unref" o = IndexEntriesUnrefMethodInfo
    ResolveIndexEntriesMethod "getByIndex" o = IndexEntriesGetByIndexMethodInfo
    ResolveIndexEntriesMethod "getByPath" o = IndexEntriesGetByPathMethodInfo
    ResolveIndexEntriesMethod l o = O.MethodResolutionFailed l o

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

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