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

Represents an annotated commit object.
-}

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

module GI.Ggit.Structs.AnnotatedCommit
    (

-- * Exported types
    AnnotatedCommit(..)                     ,
    noAnnotatedCommit                       ,


 -- * Methods
-- ** getId #method:getId#

#if ENABLE_OVERLOADING
    AnnotatedCommitGetIdMethodInfo          ,
#endif
    annotatedCommitGetId                    ,


-- ** newFromRef #method:newFromRef#

    annotatedCommitNewFromRef               ,


-- ** ref #method:ref#

#if ENABLE_OVERLOADING
    AnnotatedCommitRefMethodInfo            ,
#endif
    annotatedCommitRef                      ,


-- ** unref #method:unref#

#if ENABLE_OVERLOADING
    AnnotatedCommitUnrefMethodInfo          ,
#endif
    annotatedCommitUnref                    ,




    ) 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.GClosure as B.GClosure
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.GI.Base.Properties as B.Properties
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 GHC.OverloadedLabels as OL

import {-# SOURCE #-} qualified GI.Ggit.Objects.Ref as Ggit.Ref
import {-# SOURCE #-} qualified GI.Ggit.Objects.Repository as Ggit.Repository
import {-# SOURCE #-} qualified GI.Ggit.Structs.OId as Ggit.OId

-- | Memory-managed wrapper type.
newtype AnnotatedCommit = AnnotatedCommit (ManagedPtr AnnotatedCommit)
foreign import ccall "ggit_annotated_commit_get_type" c_ggit_annotated_commit_get_type ::
    IO GType

instance BoxedObject AnnotatedCommit where
    boxedType _ = c_ggit_annotated_commit_get_type

-- | A convenience alias for `Nothing` :: `Maybe` `AnnotatedCommit`.
noAnnotatedCommit :: Maybe AnnotatedCommit
noAnnotatedCommit = Nothing


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

-- method AnnotatedCommit::new_from_ref
-- method type : Constructor
-- Args : [Arg {argCName = "repository", argType = TInterface (Name {namespace = "Ggit", name = "Repository"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the repository", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "ref", argType = TInterface (Name {namespace = "Ggit", name = "Ref"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the reference to use to lookup the git_annotated_commit", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "AnnotatedCommit"}))
-- throws : True
-- Skip return : False

foreign import ccall "ggit_annotated_commit_new_from_ref" ggit_annotated_commit_new_from_ref ::
    Ptr Ggit.Repository.Repository ->       -- repository : TInterface (Name {namespace = "Ggit", name = "Repository"})
    Ptr Ggit.Ref.Ref ->                     -- ref : TInterface (Name {namespace = "Ggit", name = "Ref"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr AnnotatedCommit)

{- |
Create a GgitAnnotatedCommit from the given reference
-}
annotatedCommitNewFromRef ::
    (B.CallStack.HasCallStack, MonadIO m, Ggit.Repository.IsRepository a, Ggit.Ref.IsRef b) =>
    a
    {- ^ /@repository@/: the repository -}
    -> b
    {- ^ /@ref@/: the reference to use to lookup the git_annotated_commit -}
    -> m AnnotatedCommit
    {- ^ __Returns:__ a 'GI.Ggit.Structs.AnnotatedCommit.AnnotatedCommit'. /(Can throw 'Data.GI.Base.GError.GError')/ -}
annotatedCommitNewFromRef repository ref = liftIO $ do
    repository' <- unsafeManagedPtrCastPtr repository
    ref' <- unsafeManagedPtrCastPtr ref
    onException (do
        result <- propagateGError $ ggit_annotated_commit_new_from_ref repository' ref'
        checkUnexpectedReturnNULL "annotatedCommitNewFromRef" result
        result' <- (wrapBoxed AnnotatedCommit) result
        touchManagedPtr repository
        touchManagedPtr ref
        return result'
     ) (do
        return ()
     )

#if ENABLE_OVERLOADING
#endif

-- method AnnotatedCommit::get_id
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "annotated_commit", argType = TInterface (Name {namespace = "Ggit", name = "AnnotatedCommit"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitAnnotatedCommit.", 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_annotated_commit_get_id" ggit_annotated_commit_get_id ::
    Ptr AnnotatedCommit ->                  -- annotated_commit : TInterface (Name {namespace = "Ggit", name = "AnnotatedCommit"})
    IO (Ptr Ggit.OId.OId)

{- |
Gets the commit ID that the given /@annotatedCommit@/ refs to.
-}
annotatedCommitGetId ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    AnnotatedCommit
    {- ^ /@annotatedCommit@/: a 'GI.Ggit.Structs.AnnotatedCommit.AnnotatedCommit'. -}
    -> m (Maybe Ggit.OId.OId)
    {- ^ __Returns:__ the commit ID that the given /@annotatedCommit@/ refs to or 'Nothing'. -}
annotatedCommitGetId annotatedCommit = liftIO $ do
    annotatedCommit' <- unsafeManagedPtrGetPtr annotatedCommit
    result <- ggit_annotated_commit_get_id annotatedCommit'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed Ggit.OId.OId) result'
        return result''
    touchManagedPtr annotatedCommit
    return maybeResult

#if ENABLE_OVERLOADING
data AnnotatedCommitGetIdMethodInfo
instance (signature ~ (m (Maybe Ggit.OId.OId)), MonadIO m) => O.MethodInfo AnnotatedCommitGetIdMethodInfo AnnotatedCommit signature where
    overloadedMethod _ = annotatedCommitGetId

#endif

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

foreign import ccall "ggit_annotated_commit_ref" ggit_annotated_commit_ref ::
    Ptr AnnotatedCommit ->                  -- annotated_commit : TInterface (Name {namespace = "Ggit", name = "AnnotatedCommit"})
    IO (Ptr AnnotatedCommit)

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

#if ENABLE_OVERLOADING
data AnnotatedCommitRefMethodInfo
instance (signature ~ (m (Maybe AnnotatedCommit)), MonadIO m) => O.MethodInfo AnnotatedCommitRefMethodInfo AnnotatedCommit signature where
    overloadedMethod _ = annotatedCommitRef

#endif

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

foreign import ccall "ggit_annotated_commit_unref" ggit_annotated_commit_unref ::
    Ptr AnnotatedCommit ->                  -- annotated_commit : TInterface (Name {namespace = "Ggit", name = "AnnotatedCommit"})
    IO ()

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

#if ENABLE_OVERLOADING
data AnnotatedCommitUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo AnnotatedCommitUnrefMethodInfo AnnotatedCommit signature where
    overloadedMethod _ = annotatedCommitUnref

#endif

#if ENABLE_OVERLOADING
type family ResolveAnnotatedCommitMethod (t :: Symbol) (o :: *) :: * where
    ResolveAnnotatedCommitMethod "ref" o = AnnotatedCommitRefMethodInfo
    ResolveAnnotatedCommitMethod "unref" o = AnnotatedCommitUnrefMethodInfo
    ResolveAnnotatedCommitMethod "getId" o = AnnotatedCommitGetIdMethodInfo
    ResolveAnnotatedCommitMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveAnnotatedCommitMethod t AnnotatedCommit, O.MethodInfo info AnnotatedCommit p) => OL.IsLabel t (AnnotatedCommit -> 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