{-# 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(..)                                ,


 -- * 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.BasicTypes as B.Types
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 Control.Monad.IO.Class as MIO
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 (SP.ManagedPtr Note)
    deriving (Note -> Note -> Bool
(Note -> Note -> Bool) -> (Note -> Note -> Bool) -> Eq Note
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Note -> Note -> Bool
$c/= :: Note -> Note -> Bool
== :: Note -> Note -> Bool
$c== :: Note -> Note -> Bool
Eq)

instance SP.ManagedPtrNewtype Note where
    toManagedPtr :: Note -> ManagedPtr Note
toManagedPtr (Note ManagedPtr Note
p) = ManagedPtr Note
p

foreign import ccall "ggit_note_get_type" c_ggit_note_get_type :: 
    IO GType

type instance O.ParentTypes Note = '[]
instance O.HasParentTypes Note

instance B.Types.TypedObject Note where
    glibType :: IO GType
glibType = IO GType
c_ggit_note_get_type

instance B.Types.GBoxed Note

-- | 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 :: Note -> IO GValue
toGValue Note
o = do
        GType
gtype <- IO GType
c_ggit_note_get_type
        Note -> (Ptr Note -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Note
o (GType -> (GValue -> Ptr Note -> IO ()) -> Ptr Note -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr Note -> IO ()
forall a. GValue -> Ptr a -> IO ()
B.GValue.set_boxed)
        
    fromGValue :: GValue -> IO Note
fromGValue GValue
gv = do
        Ptr Note
ptr <- GValue -> IO (Ptr Note)
forall b. GValue -> IO (Ptr b)
B.GValue.get_boxed GValue
gv :: IO (Ptr Note)
        (ManagedPtr Note -> Note) -> Ptr Note -> IO Note
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
B.ManagedPtr.newBoxed ManagedPtr Note -> Note
Note Ptr Note
ptr
        
    


#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 -> m (Maybe OId)
noteGetId Note
note = IO (Maybe OId) -> m (Maybe OId)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe OId) -> m (Maybe OId))
-> IO (Maybe OId) -> m (Maybe OId)
forall a b. (a -> b) -> a -> b
$ do
    Ptr Note
note' <- Note -> IO (Ptr Note)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Note
note
    Ptr OId
result <- Ptr Note -> IO (Ptr OId)
ggit_note_get_id Ptr Note
note'
    Maybe OId
maybeResult <- Ptr OId -> (Ptr OId -> IO OId) -> IO (Maybe OId)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr OId
result ((Ptr OId -> IO OId) -> IO (Maybe OId))
-> (Ptr OId -> IO OId) -> IO (Maybe OId)
forall a b. (a -> b) -> a -> b
$ \Ptr OId
result' -> do
        OId
result'' <- ((ManagedPtr OId -> OId) -> Ptr OId -> IO OId
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
newBoxed ManagedPtr OId -> OId
Ggit.OId.OId) Ptr OId
result'
        OId -> IO OId
forall (m :: * -> *) a. Monad m => a -> m a
return OId
result''
    Note -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Note
note
    Maybe OId -> IO (Maybe OId)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe OId
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 -> m (Maybe Text)
noteGetMessage Note
note = IO (Maybe Text) -> m (Maybe Text)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Text) -> m (Maybe Text))
-> IO (Maybe Text) -> m (Maybe Text)
forall a b. (a -> b) -> a -> b
$ do
    Ptr Note
note' <- Note -> IO (Ptr Note)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Note
note
    CString
result <- Ptr Note -> IO CString
ggit_note_get_message Ptr Note
note'
    Maybe Text
maybeResult <- CString -> (CString -> IO Text) -> IO (Maybe Text)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull CString
result ((CString -> IO Text) -> IO (Maybe Text))
-> (CString -> IO Text) -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \CString
result' -> do
        Text
result'' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result'
        Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result''
    Note -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Note
note
    Maybe Text -> IO (Maybe Text)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Text
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 -> m (Maybe Note)
noteRef Note
note = IO (Maybe Note) -> m (Maybe Note)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Note) -> m (Maybe Note))
-> IO (Maybe Note) -> m (Maybe Note)
forall a b. (a -> b) -> a -> b
$ do
    Ptr Note
note' <- Note -> IO (Ptr Note)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Note
note
    Ptr Note
result <- Ptr Note -> IO (Ptr Note)
ggit_note_ref Ptr Note
note'
    Maybe Note
maybeResult <- Ptr Note -> (Ptr Note -> IO Note) -> IO (Maybe Note)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr Note
result ((Ptr Note -> IO Note) -> IO (Maybe Note))
-> (Ptr Note -> IO Note) -> IO (Maybe Note)
forall a b. (a -> b) -> a -> b
$ \Ptr Note
result' -> do
        Note
result'' <- ((ManagedPtr Note -> Note) -> Ptr Note -> IO Note
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
newBoxed ManagedPtr Note -> Note
Note) Ptr Note
result'
        Note -> IO Note
forall (m :: * -> *) a. Monad m => a -> m a
return Note
result''
    Note -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Note
note
    Maybe Note -> IO (Maybe Note)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Note
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 -> m ()
noteUnref Note
note = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Note
note' <- Note -> IO (Ptr Note)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Note
note
    Ptr Note -> IO ()
ggit_note_unref Ptr Note
note'
    Note -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Note
note
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
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