{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- Represents an annotated commit object.

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

module GI.Ggit.Structs.AnnotatedCommit
    (

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


 -- * Methods
-- ** Overloaded methods #method:Overloaded methods#

#if defined(ENABLE_OVERLOADING)
    ResolveAnnotatedCommitMethod            ,
#endif


-- ** getId #method:getId#

#if defined(ENABLE_OVERLOADING)
    AnnotatedCommitGetIdMethodInfo          ,
#endif
    annotatedCommitGetId                    ,


-- ** newFromRef #method:newFromRef#

    annotatedCommitNewFromRef               ,


-- ** ref #method:ref#

#if defined(ENABLE_OVERLOADING)
    AnnotatedCommitRefMethodInfo            ,
#endif
    annotatedCommitRef                      ,


-- ** unref #method:unref#

#if defined(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.GI.Base.Signals as B.Signals
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)
    deriving (Eq)
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

-- | Convert 'AnnotatedCommit' to and from 'Data.GI.Base.GValue.GValue' with 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue AnnotatedCommit where
    toGValue o = do
        gtype <- c_ggit_annotated_commit_get_type
        B.ManagedPtr.withManagedPtr o (B.GValue.buildGValue gtype B.GValue.set_boxed)

    fromGValue gv = do
        ptr <- B.GValue.get_boxed gv :: IO (Ptr AnnotatedCommit)
        B.ManagedPtr.newBoxed AnnotatedCommit ptr



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


#if defined(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 t'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 defined(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 t'GI.Ggit.Structs.AnnotatedCommit.AnnotatedCommit'.
    -> m (Maybe Ggit.OId.OId)
    -- ^ __Returns:__ the commit ID that the given /@annotatedCommit@/ refs to or 'P.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 defined(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 t'GI.Ggit.Structs.AnnotatedCommit.AnnotatedCommit'.
    -> m (Maybe AnnotatedCommit)
    -- ^ __Returns:__ a newly allocated t'GI.Ggit.Structs.AnnotatedCommit.AnnotatedCommit' or 'P.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 defined(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 t'GI.Ggit.Structs.AnnotatedCommit.AnnotatedCommit'.
    -> m ()
annotatedCommitUnref annotatedCommit = liftIO $ do
    annotatedCommit' <- unsafeManagedPtrGetPtr annotatedCommit
    ggit_annotated_commit_unref annotatedCommit'
    touchManagedPtr annotatedCommit
    return ()

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

#endif

#if defined(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 @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#endif