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

module GI.Ggit.Structs.Note
    ( 

-- * Exported types
    Note(..)                                ,
    noNote                                  ,


 -- * Methods
-- ** getId #method:getId#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    NoteGetIdMethodInfo                     ,
#endif
    noteGetId                               ,


-- ** getMessage #method:getMessage#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    NoteGetMessageMethodInfo                ,
#endif
    noteGetMessage                          ,


-- ** ref #method:ref#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    NoteRefMethodInfo                       ,
#endif
    noteRef                                 ,


-- ** unref #method:unref#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    NoteUnrefMethodInfo                     ,
#endif
    noteUnref                               ,




    ) 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 {-# SOURCE #-} qualified GI.Ggit.Structs.OId as Ggit.OId

newtype Note = Note (ManagedPtr Note)
foreign import ccall "ggit_note_get_type" c_ggit_note_get_type :: 
    IO GType

instance BoxedObject Note where
    boxedType _ = c_ggit_note_get_type

noNote :: Maybe Note
noNote = Nothing


#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
instance O.HasAttributeList Note
type instance O.AttributeList Note = NoteAttributeList
type NoteAttributeList = ('[ ] :: [(Symbol, *)])
#endif

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

{- |
Gets the note object\'s id.
-}
noteGetId ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Note
    {- ^ /@note@/: a 'GI.Ggit.Structs.Note.Note'. -}
    -> m Ggit.OId.OId
    {- ^ __Returns:__ the object\'s id. -}
noteGetId note = liftIO $ do
    note' <- unsafeManagedPtrGetPtr note
    result <- ggit_note_get_id note'
    checkUnexpectedReturnNULL "noteGetId" result
    result' <- (newBoxed Ggit.OId.OId) result
    touchManagedPtr note
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data NoteGetIdMethodInfo
instance (signature ~ (m Ggit.OId.OId), MonadIO m) => O.MethodInfo NoteGetIdMethodInfo Note signature where
    overloadedMethod _ = noteGetId

#endif

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

foreign import ccall "ggit_note_get_message" ggit_note_get_message :: 
    Ptr Note ->                             -- note : TInterface (Name {namespace = "Ggit", name = "Note"})
    IO CString

{- |
Gets the note message.
-}
noteGetMessage ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Note
    {- ^ /@note@/: a 'GI.Ggit.Structs.Note.Note'. -}
    -> m T.Text
    {- ^ __Returns:__ the note message. -}
noteGetMessage note = liftIO $ do
    note' <- unsafeManagedPtrGetPtr note
    result <- ggit_note_get_message note'
    checkUnexpectedReturnNULL "noteGetMessage" result
    result' <- cstringToText result
    touchManagedPtr note
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data NoteGetMessageMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.MethodInfo NoteGetMessageMethodInfo Note signature where
    overloadedMethod _ = noteGetMessage

#endif

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

foreign import ccall "ggit_note_ref" ggit_note_ref :: 
    Ptr Note ->                             -- note : TInterface (Name {namespace = "Ggit", name = "Note"})
    IO (Ptr Note)

{- |
Atomically increments the reference count of /@note@/ by one.
This function is MT-safe and may be called from any thread.
-}
noteRef ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Note
    {- ^ /@note@/: a 'GI.Ggit.Structs.Note.Note'. -}
    -> m Note
    {- ^ __Returns:__ a 'GI.Ggit.Structs.Note.Note'. -}
noteRef note = liftIO $ do
    note' <- unsafeManagedPtrGetPtr note
    result <- ggit_note_ref note'
    checkUnexpectedReturnNULL "noteRef" result
    result' <- (wrapBoxed Note) result
    touchManagedPtr note
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data NoteRefMethodInfo
instance (signature ~ (m Note), MonadIO m) => O.MethodInfo NoteRefMethodInfo Note signature where
    overloadedMethod _ = noteRef

#endif

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

foreign import ccall "ggit_note_unref" ggit_note_unref :: 
    Ptr Note ->                             -- note : TInterface (Name {namespace = "Ggit", name = "Note"})
    IO ()

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

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data NoteUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo NoteUnrefMethodInfo Note signature where
    overloadedMethod _ = noteUnref

#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type family ResolveNoteMethod (t :: Symbol) (o :: *) :: * where
    ResolveNoteMethod "ref" o = NoteRefMethodInfo
    ResolveNoteMethod "unref" o = NoteUnrefMethodInfo
    ResolveNoteMethod "getId" o = NoteGetIdMethodInfo
    ResolveNoteMethod "getMessage" o = NoteGetMessageMethodInfo
    ResolveNoteMethod l o = O.MethodResolutionFailed l o

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

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