{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)

Represents a tag object.
-}

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

module GI.Ggit.Objects.Tag
    (

-- * Exported types
    Tag(..)                                 ,
    IsTag                                   ,
    toTag                                   ,
    noTag                                   ,


 -- * Methods
-- ** getMessage #method:getMessage#

#if ENABLE_OVERLOADING
    TagGetMessageMethodInfo                 ,
#endif
    tagGetMessage                           ,


-- ** getName #method:getName#

#if ENABLE_OVERLOADING
    TagGetNameMethodInfo                    ,
#endif
    tagGetName                              ,


-- ** getTagger #method:getTagger#

#if ENABLE_OVERLOADING
    TagGetTaggerMethodInfo                  ,
#endif
    tagGetTagger                            ,


-- ** getTarget #method:getTarget#

#if ENABLE_OVERLOADING
    TagGetTargetMethodInfo                  ,
#endif
    tagGetTarget                            ,


-- ** getTargetId #method:getTargetId#

#if ENABLE_OVERLOADING
    TagGetTargetIdMethodInfo                ,
#endif
    tagGetTargetId                          ,


-- ** getTargetType #method:getTargetType#

#if ENABLE_OVERLOADING
    TagGetTargetTypeMethodInfo              ,
#endif
    tagGetTargetType                        ,


-- ** peel #method:peel#

#if ENABLE_OVERLOADING
    TagPeelMethodInfo                       ,
#endif
    tagPeel                                 ,




    ) 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.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 GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Ggit.Objects.Native as Ggit.Native
import {-# SOURCE #-} qualified GI.Ggit.Objects.Object as Ggit.Object
import {-# SOURCE #-} qualified GI.Ggit.Objects.ObjectFactoryBase as Ggit.ObjectFactoryBase
import {-# SOURCE #-} qualified GI.Ggit.Objects.Signature as Ggit.Signature
import {-# SOURCE #-} qualified GI.Ggit.Structs.OId as Ggit.OId

-- | Memory-managed wrapper type.
newtype Tag = Tag (ManagedPtr Tag)
foreign import ccall "ggit_tag_get_type"
    c_ggit_tag_get_type :: IO GType

instance GObject Tag where
    gobjectType = c_ggit_tag_get_type


-- | Type class for types which can be safely cast to `Tag`, for instance with `toTag`.
class (GObject o, O.IsDescendantOf Tag o) => IsTag o
instance (GObject o, O.IsDescendantOf Tag o) => IsTag o

instance O.HasParentTypes Tag
type instance O.ParentTypes Tag = '[Ggit.Object.Object, Ggit.Native.Native, Ggit.ObjectFactoryBase.ObjectFactoryBase, GObject.Object.Object]

-- | Cast to `Tag`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toTag :: (MonadIO m, IsTag o) => o -> m Tag
toTag = liftIO . unsafeCastTo Tag

-- | A convenience alias for `Nothing` :: `Maybe` `Tag`.
noTag :: Maybe Tag
noTag = Nothing

#if ENABLE_OVERLOADING
type family ResolveTagMethod (t :: Symbol) (o :: *) :: * where
    ResolveTagMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveTagMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveTagMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveTagMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveTagMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveTagMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveTagMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveTagMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveTagMethod "peel" o = TagPeelMethodInfo
    ResolveTagMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveTagMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveTagMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveTagMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveTagMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveTagMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveTagMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveTagMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveTagMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveTagMethod "getId" o = Ggit.Object.ObjectGetIdMethodInfo
    ResolveTagMethod "getMessage" o = TagGetMessageMethodInfo
    ResolveTagMethod "getName" o = TagGetNameMethodInfo
    ResolveTagMethod "getOwner" o = Ggit.Object.ObjectGetOwnerMethodInfo
    ResolveTagMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveTagMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveTagMethod "getTagger" o = TagGetTaggerMethodInfo
    ResolveTagMethod "getTarget" o = TagGetTargetMethodInfo
    ResolveTagMethod "getTargetId" o = TagGetTargetIdMethodInfo
    ResolveTagMethod "getTargetType" o = TagGetTargetTypeMethodInfo
    ResolveTagMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveTagMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveTagMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveTagMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveTagMethod t Tag, O.MethodInfo info Tag p) => OL.IsLabel t (Tag -> 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

#if ENABLE_OVERLOADING
instance O.HasAttributeList Tag
type instance O.AttributeList Tag = TagAttributeList
type TagAttributeList = ('[ '("native", Ggit.Native.NativeNativePropertyInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
#endif

#if ENABLE_OVERLOADING
type instance O.SignalList Tag = TagSignalList
type TagSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method Tag::get_message
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "tag", argType = TInterface (Name {namespace = "Ggit", name = "Tag"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitTag.", 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_tag_get_message" ggit_tag_get_message ::
    Ptr Tag ->                              -- tag : TInterface (Name {namespace = "Ggit", name = "Tag"})
    IO CString

{- |
Gets the message of /@tag@/.
-}
tagGetMessage ::
    (B.CallStack.HasCallStack, MonadIO m, IsTag a) =>
    a
    {- ^ /@tag@/: a 'GI.Ggit.Objects.Tag.Tag'. -}
    -> m (Maybe T.Text)
    {- ^ __Returns:__ the message of the tag or 'Nothing'. -}
tagGetMessage tag = liftIO $ do
    tag' <- unsafeManagedPtrCastPtr tag
    result <- ggit_tag_get_message tag'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToText result'
        return result''
    touchManagedPtr tag
    return maybeResult

#if ENABLE_OVERLOADING
data TagGetMessageMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m, IsTag a) => O.MethodInfo TagGetMessageMethodInfo a signature where
    overloadedMethod _ = tagGetMessage

#endif

-- method Tag::get_name
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "tag", argType = TInterface (Name {namespace = "Ggit", name = "Tag"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitTag.", 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_tag_get_name" ggit_tag_get_name ::
    Ptr Tag ->                              -- tag : TInterface (Name {namespace = "Ggit", name = "Tag"})
    IO CString

{- |
Gets the name of /@tag@/.
-}
tagGetName ::
    (B.CallStack.HasCallStack, MonadIO m, IsTag a) =>
    a
    {- ^ /@tag@/: a 'GI.Ggit.Objects.Tag.Tag'. -}
    -> m (Maybe T.Text)
    {- ^ __Returns:__ the name of the tag or 'Nothing'. -}
tagGetName tag = liftIO $ do
    tag' <- unsafeManagedPtrCastPtr tag
    result <- ggit_tag_get_name tag'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToText result'
        return result''
    touchManagedPtr tag
    return maybeResult

#if ENABLE_OVERLOADING
data TagGetNameMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m, IsTag a) => O.MethodInfo TagGetNameMethodInfo a signature where
    overloadedMethod _ = tagGetName

#endif

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

foreign import ccall "ggit_tag_get_tagger" ggit_tag_get_tagger ::
    Ptr Tag ->                              -- tag : TInterface (Name {namespace = "Ggit", name = "Tag"})
    IO (Ptr Ggit.Signature.Signature)

{- |
Get the tagger (author) of /@tag@/. The returned value must be free with
'GI.GObject.Objects.Object.objectUnref'.
-}
tagGetTagger ::
    (B.CallStack.HasCallStack, MonadIO m, IsTag a) =>
    a
    {- ^ /@tag@/: a 'GI.Ggit.Objects.Tag.Tag'. -}
    -> m (Maybe Ggit.Signature.Signature)
    {- ^ __Returns:__ the tagger (author) of the tag or 'Nothing'. -}
tagGetTagger tag = liftIO $ do
    tag' <- unsafeManagedPtrCastPtr tag
    result <- ggit_tag_get_tagger tag'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapObject Ggit.Signature.Signature) result'
        return result''
    touchManagedPtr tag
    return maybeResult

#if ENABLE_OVERLOADING
data TagGetTaggerMethodInfo
instance (signature ~ (m (Maybe Ggit.Signature.Signature)), MonadIO m, IsTag a) => O.MethodInfo TagGetTaggerMethodInfo a signature where
    overloadedMethod _ = tagGetTagger

#endif

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

foreign import ccall "ggit_tag_get_target" ggit_tag_get_target ::
    Ptr Tag ->                              -- tag : TInterface (Name {namespace = "Ggit", name = "Tag"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Ggit.Object.Object)

{- |
Gets the target 'GI.Ggit.Objects.Object.Object' of /@tag@/.

This method performs a repository lookup for the
given object and returns it.
-}
tagGetTarget ::
    (B.CallStack.HasCallStack, MonadIO m, IsTag a) =>
    a
    {- ^ /@tag@/: a 'GI.Ggit.Objects.Tag.Tag'. -}
    -> m (Maybe Ggit.Object.Object)
    {- ^ __Returns:__ the target 'GI.Ggit.Objects.Object.Object' of the tag or 'Nothing'. /(Can throw 'Data.GI.Base.GError.GError')/ -}
tagGetTarget tag = liftIO $ do
    tag' <- unsafeManagedPtrCastPtr tag
    onException (do
        result <- propagateGError $ ggit_tag_get_target tag'
        maybeResult <- convertIfNonNull result $ \result' -> do
            result'' <- (wrapObject Ggit.Object.Object) result'
            return result''
        touchManagedPtr tag
        return maybeResult
     ) (do
        return ()
     )

#if ENABLE_OVERLOADING
data TagGetTargetMethodInfo
instance (signature ~ (m (Maybe Ggit.Object.Object)), MonadIO m, IsTag a) => O.MethodInfo TagGetTargetMethodInfo a signature where
    overloadedMethod _ = tagGetTarget

#endif

-- method Tag::get_target_id
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "tag", argType = TInterface (Name {namespace = "Ggit", name = "Tag"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitTag.", 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_tag_get_target_id" ggit_tag_get_target_id ::
    Ptr Tag ->                              -- tag : TInterface (Name {namespace = "Ggit", name = "Tag"})
    IO (Ptr Ggit.OId.OId)

{- |
Gets the target 'GI.Ggit.Structs.OId.OId' of /@tag@/.
-}
tagGetTargetId ::
    (B.CallStack.HasCallStack, MonadIO m, IsTag a) =>
    a
    {- ^ /@tag@/: a 'GI.Ggit.Objects.Tag.Tag'. -}
    -> m (Maybe Ggit.OId.OId)
    {- ^ __Returns:__ the target 'GI.Ggit.Structs.OId.OId' of the tag or 'Nothing'. -}
tagGetTargetId tag = liftIO $ do
    tag' <- unsafeManagedPtrCastPtr tag
    result <- ggit_tag_get_target_id tag'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed Ggit.OId.OId) result'
        return result''
    touchManagedPtr tag
    return maybeResult

#if ENABLE_OVERLOADING
data TagGetTargetIdMethodInfo
instance (signature ~ (m (Maybe Ggit.OId.OId)), MonadIO m, IsTag a) => O.MethodInfo TagGetTargetIdMethodInfo a signature where
    overloadedMethod _ = tagGetTargetId

#endif

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

foreign import ccall "ggit_tag_get_target_type" ggit_tag_get_target_type ::
    Ptr Tag ->                              -- tag : TInterface (Name {namespace = "Ggit", name = "Tag"})
    IO CGType

{- |
Get the target object type.
-}
tagGetTargetType ::
    (B.CallStack.HasCallStack, MonadIO m, IsTag a) =>
    a
    {- ^ /@tag@/: a 'GI.Ggit.Objects.Tag.Tag'. -}
    -> m GType
    {- ^ __Returns:__ a 'GType'. -}
tagGetTargetType tag = liftIO $ do
    tag' <- unsafeManagedPtrCastPtr tag
    result <- ggit_tag_get_target_type tag'
    let result' = GType result
    touchManagedPtr tag
    return result'

#if ENABLE_OVERLOADING
data TagGetTargetTypeMethodInfo
instance (signature ~ (m GType), MonadIO m, IsTag a) => O.MethodInfo TagGetTargetTypeMethodInfo a signature where
    overloadedMethod _ = tagGetTargetType

#endif

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

foreign import ccall "ggit_tag_peel" ggit_tag_peel ::
    Ptr Tag ->                              -- tag : TInterface (Name {namespace = "Ggit", name = "Tag"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Ggit.Object.Object)

{- |
Recursively peel a tag until a non tag object is found.
-}
tagPeel ::
    (B.CallStack.HasCallStack, MonadIO m, IsTag a) =>
    a
    {- ^ /@tag@/: a 'GI.Ggit.Objects.Tag.Tag'. -}
    -> m (Maybe Ggit.Object.Object)
    {- ^ __Returns:__ a 'GI.Ggit.Objects.Object.Object' or 'Nothing'. /(Can throw 'Data.GI.Base.GError.GError')/ -}
tagPeel tag = liftIO $ do
    tag' <- unsafeManagedPtrCastPtr tag
    onException (do
        result <- propagateGError $ ggit_tag_peel tag'
        maybeResult <- convertIfNonNull result $ \result' -> do
            result'' <- (wrapObject Ggit.Object.Object) result'
            return result''
        touchManagedPtr tag
        return maybeResult
     ) (do
        return ()
     )

#if ENABLE_OVERLOADING
data TagPeelMethodInfo
instance (signature ~ (m (Maybe Ggit.Object.Object)), MonadIO m, IsTag a) => O.MethodInfo TagPeelMethodInfo a signature where
    overloadedMethod _ = tagPeel

#endif