{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- 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
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [ref]("GI.Ggit.Structs.Note#g:method:ref"), [unref]("GI.Ggit.Structs.Note#g:method:unref").
-- 
-- ==== Getters
-- [getId]("GI.Ggit.Structs.Note#g:method:getId"), [getMessage]("GI.Ggit.Structs.Note#g:method:getMessage").
-- 
-- ==== Setters
-- /None/.

#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.GArray as B.GArray
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.Coerce as Coerce
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 qualified GHC.Records as R

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'. See 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue (Maybe Note) where
    gvalueGType_ :: IO GType
gvalueGType_ = IO GType
c_ggit_note_get_type
    gvalueSet_ :: Ptr GValue -> Maybe Note -> IO ()
gvalueSet_ Ptr GValue
gv Maybe Note
P.Nothing = Ptr GValue -> Ptr Note -> IO ()
forall a. Ptr GValue -> Ptr a -> IO ()
B.GValue.set_boxed Ptr GValue
gv (Ptr Note
forall a. Ptr a
FP.nullPtr :: FP.Ptr Note)
    gvalueSet_ Ptr GValue
gv (P.Just Note
obj) = Note -> (Ptr Note -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Note
obj (Ptr GValue -> Ptr Note -> IO ()
forall a. Ptr GValue -> Ptr a -> IO ()
B.GValue.set_boxed Ptr GValue
gv)
    gvalueGet_ :: Ptr GValue -> IO (Maybe Note)
gvalueGet_ Ptr GValue
gv = do
        Ptr Note
ptr <- Ptr GValue -> IO (Ptr Note)
forall b. Ptr GValue -> IO (Ptr b)
B.GValue.get_boxed Ptr GValue
gv :: IO (Ptr Note)
        if Ptr Note
ptr Ptr Note -> Ptr Note -> Bool
forall a. Eq a => a -> a -> Bool
/= Ptr Note
forall a. Ptr a
FP.nullPtr
        then Note -> Maybe Note
forall a. a -> Maybe a
P.Just (Note -> Maybe Note) -> IO Note -> IO (Maybe Note)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (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
        else Maybe Note -> IO (Maybe Note)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Note
forall a. Maybe a
P.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 :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
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.OverloadedMethod NoteGetIdMethodInfo Note signature where
    overloadedMethod = noteGetId

instance O.OverloadedMethodInfo NoteGetIdMethodInfo Note where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Ggit.Structs.Note.noteGetId",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-ggit-1.0.11/docs/GI-Ggit-Structs-Note.html#v: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 :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
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.OverloadedMethod NoteGetMessageMethodInfo Note signature where
    overloadedMethod = noteGetMessage

instance O.OverloadedMethodInfo NoteGetMessageMethodInfo Note where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Ggit.Structs.Note.noteGetMessage",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-ggit-1.0.11/docs/GI-Ggit-Structs-Note.html#v: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 :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
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.OverloadedMethod NoteRefMethodInfo Note signature where
    overloadedMethod = noteRef

instance O.OverloadedMethodInfo NoteRefMethodInfo Note where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Ggit.Structs.Note.noteRef",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-ggit-1.0.11/docs/GI-Ggit-Structs-Note.html#v: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 :: forall (m :: * -> *). (HasCallStack, MonadIO m) => 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.OverloadedMethod NoteUnrefMethodInfo Note signature where
    overloadedMethod = noteUnref

instance O.OverloadedMethodInfo NoteUnrefMethodInfo Note where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Ggit.Structs.Note.noteUnref",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-ggit-1.0.11/docs/GI-Ggit-Structs-Note.html#v: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.OverloadedMethod 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

#if MIN_VERSION_base(4,13,0)
instance (info ~ ResolveNoteMethod t Note, O.OverloadedMethod info Note p, R.HasField t Note p) => R.HasField t Note p where
    getField = O.overloadedMethod @info

#endif

instance (info ~ ResolveNoteMethod t Note, O.OverloadedMethodInfo info Note) => OL.IsLabel t (O.MethodProxy info Note) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.MethodProxy
#else
    fromLabel _ = O.MethodProxy
#endif

#endif