{-# LANGUAGE TypeApplications #-}


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

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

module GI.Ggit.Structs.Note
    (

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


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

#if defined(ENABLE_OVERLOADING)
    ResolveNoteMethod                       ,
#endif


-- ** getId #method:getId#

#if defined(ENABLE_OVERLOADING)
    NoteGetIdMethodInfo                     ,
#endif
    noteGetId                               ,


-- ** getMessage #method:getMessage#

#if defined(ENABLE_OVERLOADING)
    NoteGetMessageMethodInfo                ,
#endif
    noteGetMessage                          ,


-- ** ref #method:ref#

#if defined(ENABLE_OVERLOADING)
    NoteRefMethodInfo                       ,
#endif
    noteRef                                 ,


-- ** unref #method:unref#

#if defined(ENABLE_OVERLOADING)
    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.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.Structs.OId as Ggit.OId

-- | Memory-managed wrapper type.
newtype Note = Note (ManagedPtr Note)
    deriving (Eq)
foreign import ccall "ggit_note_get_type" c_ggit_note_get_type ::
    IO GType

instance BoxedObject Note where
    boxedType _ = c_ggit_note_get_type

-- | Convert 'Note' to and from 'Data.GI.Base.GValue.GValue' with 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue Note where
    toGValue o = do
        gtype <- c_ggit_note_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 Note)
        B.ManagedPtr.newBoxed Note ptr



-- | A convenience alias for `Nothing` :: `Maybe` `Note`.
noNote :: Maybe Note
noNote = Nothing


#if defined(ENABLE_OVERLOADING)
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 t'GI.Ggit.Structs.Note.Note'.
    -> m (Maybe Ggit.OId.OId)
    -- ^ __Returns:__ the object\'s id or 'P.Nothing'.
noteGetId note = liftIO $ do
    note' <- unsafeManagedPtrGetPtr note
    result <- ggit_note_get_id note'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (newBoxed Ggit.OId.OId) result'
        return result''
    touchManagedPtr note
    return maybeResult

#if defined(ENABLE_OVERLOADING)
data NoteGetIdMethodInfo
instance (signature ~ (m (Maybe 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 t'GI.Ggit.Structs.Note.Note'.
    -> m (Maybe T.Text)
    -- ^ __Returns:__ the note message or 'P.Nothing'.
noteGetMessage note = liftIO $ do
    note' <- unsafeManagedPtrGetPtr note
    result <- ggit_note_get_message note'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToText result'
        return result''
    touchManagedPtr note
    return maybeResult

#if defined(ENABLE_OVERLOADING)
data NoteGetMessageMethodInfo
instance (signature ~ (m (Maybe 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 t'GI.Ggit.Structs.Note.Note'.
    -> m (Maybe Note)
    -- ^ __Returns:__ a t'GI.Ggit.Structs.Note.Note' or 'P.Nothing'.
noteRef note = liftIO $ do
    note' <- unsafeManagedPtrGetPtr note
    result <- ggit_note_ref note'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (newBoxed Note) result'
        return result''
    touchManagedPtr note
    return maybeResult

#if defined(ENABLE_OVERLOADING)
data NoteRefMethodInfo
instance (signature ~ (m (Maybe 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 t'GI.Ggit.Structs.Note.Note'.
    -> m ()
noteUnref note = liftIO $ do
    note' <- unsafeManagedPtrGetPtr note
    ggit_note_unref note'
    touchManagedPtr note
    return ()

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

#endif

#if defined(ENABLE_OVERLOADING)
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) => OL.IsLabel t (Note -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#endif