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

Information about an annotation.
-}

module GI.Gio.Structs.DBusAnnotationInfo
    ( 

-- * Exported types
    DBusAnnotationInfo(..)                  ,
    newZeroDBusAnnotationInfo               ,
    noDBusAnnotationInfo                    ,


 -- * Methods
-- ** lookup #method:lookup#
    dBusAnnotationInfoLookup                ,


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


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




 -- * Properties
-- ** annotations #attr:annotations#
    clearDBusAnnotationInfoAnnotations      ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    dBusAnnotationInfo_annotations          ,
#endif
    getDBusAnnotationInfoAnnotations        ,
    setDBusAnnotationInfoAnnotations        ,


-- ** key #attr:key#
    clearDBusAnnotationInfoKey              ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    dBusAnnotationInfo_key                  ,
#endif
    getDBusAnnotationInfoKey                ,
    setDBusAnnotationInfoKey                ,


-- ** refCount #attr:refCount#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    dBusAnnotationInfo_refCount             ,
#endif
    getDBusAnnotationInfoRefCount           ,
    setDBusAnnotationInfoRefCount           ,


-- ** value #attr:value#
    clearDBusAnnotationInfoValue            ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    dBusAnnotationInfo_value                ,
#endif
    getDBusAnnotationInfoValue              ,
    setDBusAnnotationInfoValue              ,




    ) 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


newtype DBusAnnotationInfo = DBusAnnotationInfo (ManagedPtr DBusAnnotationInfo)
foreign import ccall "g_dbus_annotation_info_get_type" c_g_dbus_annotation_info_get_type :: 
    IO GType

instance BoxedObject DBusAnnotationInfo where
    boxedType _ = c_g_dbus_annotation_info_get_type

-- | Construct a `DBusAnnotationInfo` struct initialized to zero.
newZeroDBusAnnotationInfo :: MonadIO m => m DBusAnnotationInfo
newZeroDBusAnnotationInfo = liftIO $ callocBoxedBytes 32 >>= wrapBoxed DBusAnnotationInfo

instance tag ~ 'AttrSet => Constructible DBusAnnotationInfo tag where
    new _ attrs = do
        o <- newZeroDBusAnnotationInfo
        GI.Attributes.set o attrs
        return o


noDBusAnnotationInfo :: Maybe DBusAnnotationInfo
noDBusAnnotationInfo = Nothing

getDBusAnnotationInfoRefCount :: MonadIO m => DBusAnnotationInfo -> m Int32
getDBusAnnotationInfoRefCount s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO Int32
    return val

setDBusAnnotationInfoRefCount :: MonadIO m => DBusAnnotationInfo -> Int32 -> m ()
setDBusAnnotationInfoRefCount s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (val :: Int32)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data DBusAnnotationInfoRefCountFieldInfo
instance AttrInfo DBusAnnotationInfoRefCountFieldInfo where
    type AttrAllowedOps DBusAnnotationInfoRefCountFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint DBusAnnotationInfoRefCountFieldInfo = (~) Int32
    type AttrBaseTypeConstraint DBusAnnotationInfoRefCountFieldInfo = (~) DBusAnnotationInfo
    type AttrGetType DBusAnnotationInfoRefCountFieldInfo = Int32
    type AttrLabel DBusAnnotationInfoRefCountFieldInfo = "ref_count"
    type AttrOrigin DBusAnnotationInfoRefCountFieldInfo = DBusAnnotationInfo
    attrGet _ = getDBusAnnotationInfoRefCount
    attrSet _ = setDBusAnnotationInfoRefCount
    attrConstruct = undefined
    attrClear _ = undefined

dBusAnnotationInfo_refCount :: AttrLabelProxy "refCount"
dBusAnnotationInfo_refCount = AttrLabelProxy

#endif


getDBusAnnotationInfoKey :: MonadIO m => DBusAnnotationInfo -> m (Maybe T.Text)
getDBusAnnotationInfoKey s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO CString
    result <- SP.convertIfNonNull val $ \val' -> do
        val'' <- cstringToText val'
        return val''
    return result

setDBusAnnotationInfoKey :: MonadIO m => DBusAnnotationInfo -> CString -> m ()
setDBusAnnotationInfoKey s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (val :: CString)

clearDBusAnnotationInfoKey :: MonadIO m => DBusAnnotationInfo -> m ()
clearDBusAnnotationInfoKey s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (FP.nullPtr :: CString)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data DBusAnnotationInfoKeyFieldInfo
instance AttrInfo DBusAnnotationInfoKeyFieldInfo where
    type AttrAllowedOps DBusAnnotationInfoKeyFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint DBusAnnotationInfoKeyFieldInfo = (~) CString
    type AttrBaseTypeConstraint DBusAnnotationInfoKeyFieldInfo = (~) DBusAnnotationInfo
    type AttrGetType DBusAnnotationInfoKeyFieldInfo = Maybe T.Text
    type AttrLabel DBusAnnotationInfoKeyFieldInfo = "key"
    type AttrOrigin DBusAnnotationInfoKeyFieldInfo = DBusAnnotationInfo
    attrGet _ = getDBusAnnotationInfoKey
    attrSet _ = setDBusAnnotationInfoKey
    attrConstruct = undefined
    attrClear _ = clearDBusAnnotationInfoKey

dBusAnnotationInfo_key :: AttrLabelProxy "key"
dBusAnnotationInfo_key = AttrLabelProxy

#endif


getDBusAnnotationInfoValue :: MonadIO m => DBusAnnotationInfo -> m (Maybe T.Text)
getDBusAnnotationInfoValue s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 16) :: IO CString
    result <- SP.convertIfNonNull val $ \val' -> do
        val'' <- cstringToText val'
        return val''
    return result

setDBusAnnotationInfoValue :: MonadIO m => DBusAnnotationInfo -> CString -> m ()
setDBusAnnotationInfoValue s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 16) (val :: CString)

clearDBusAnnotationInfoValue :: MonadIO m => DBusAnnotationInfo -> m ()
clearDBusAnnotationInfoValue s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 16) (FP.nullPtr :: CString)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data DBusAnnotationInfoValueFieldInfo
instance AttrInfo DBusAnnotationInfoValueFieldInfo where
    type AttrAllowedOps DBusAnnotationInfoValueFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint DBusAnnotationInfoValueFieldInfo = (~) CString
    type AttrBaseTypeConstraint DBusAnnotationInfoValueFieldInfo = (~) DBusAnnotationInfo
    type AttrGetType DBusAnnotationInfoValueFieldInfo = Maybe T.Text
    type AttrLabel DBusAnnotationInfoValueFieldInfo = "value"
    type AttrOrigin DBusAnnotationInfoValueFieldInfo = DBusAnnotationInfo
    attrGet _ = getDBusAnnotationInfoValue
    attrSet _ = setDBusAnnotationInfoValue
    attrConstruct = undefined
    attrClear _ = clearDBusAnnotationInfoValue

dBusAnnotationInfo_value :: AttrLabelProxy "value"
dBusAnnotationInfo_value = AttrLabelProxy

#endif


getDBusAnnotationInfoAnnotations :: MonadIO m => DBusAnnotationInfo -> m (Maybe [DBusAnnotationInfo])
getDBusAnnotationInfoAnnotations s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 24) :: IO (Ptr (Ptr DBusAnnotationInfo))
    result <- SP.convertIfNonNull val $ \val' -> do
        val'' <- unpackZeroTerminatedPtrArray val'
        val''' <- mapM (newBoxed DBusAnnotationInfo) val''
        return val'''
    return result

setDBusAnnotationInfoAnnotations :: MonadIO m => DBusAnnotationInfo -> Ptr (Ptr DBusAnnotationInfo) -> m ()
setDBusAnnotationInfoAnnotations s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 24) (val :: Ptr (Ptr DBusAnnotationInfo))

clearDBusAnnotationInfoAnnotations :: MonadIO m => DBusAnnotationInfo -> m ()
clearDBusAnnotationInfoAnnotations s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 24) (FP.nullPtr :: Ptr (Ptr DBusAnnotationInfo))

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data DBusAnnotationInfoAnnotationsFieldInfo
instance AttrInfo DBusAnnotationInfoAnnotationsFieldInfo where
    type AttrAllowedOps DBusAnnotationInfoAnnotationsFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint DBusAnnotationInfoAnnotationsFieldInfo = (~) (Ptr (Ptr DBusAnnotationInfo))
    type AttrBaseTypeConstraint DBusAnnotationInfoAnnotationsFieldInfo = (~) DBusAnnotationInfo
    type AttrGetType DBusAnnotationInfoAnnotationsFieldInfo = Maybe [DBusAnnotationInfo]
    type AttrLabel DBusAnnotationInfoAnnotationsFieldInfo = "annotations"
    type AttrOrigin DBusAnnotationInfoAnnotationsFieldInfo = DBusAnnotationInfo
    attrGet _ = getDBusAnnotationInfoAnnotations
    attrSet _ = setDBusAnnotationInfoAnnotations
    attrConstruct = undefined
    attrClear _ = clearDBusAnnotationInfoAnnotations

dBusAnnotationInfo_annotations :: AttrLabelProxy "annotations"
dBusAnnotationInfo_annotations = AttrLabelProxy

#endif



#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
instance O.HasAttributeList DBusAnnotationInfo
type instance O.AttributeList DBusAnnotationInfo = DBusAnnotationInfoAttributeList
type DBusAnnotationInfoAttributeList = ('[ '("refCount", DBusAnnotationInfoRefCountFieldInfo), '("key", DBusAnnotationInfoKeyFieldInfo), '("value", DBusAnnotationInfoValueFieldInfo), '("annotations", DBusAnnotationInfoAnnotationsFieldInfo)] :: [(Symbol, *)])
#endif

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

foreign import ccall "g_dbus_annotation_info_ref" g_dbus_annotation_info_ref :: 
    Ptr DBusAnnotationInfo ->               -- info : TInterface (Name {namespace = "Gio", name = "DBusAnnotationInfo"})
    IO (Ptr DBusAnnotationInfo)

{- |
If /@info@/ is statically allocated does nothing. Otherwise increases
the reference count.

@since 2.26
-}
dBusAnnotationInfoRef ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    DBusAnnotationInfo
    {- ^ /@info@/: A 'GI.Gio.Structs.DBusNodeInfo.DBusNodeInfo' -}
    -> m DBusAnnotationInfo
    {- ^ __Returns:__ The same /@info@/. -}
dBusAnnotationInfoRef info = liftIO $ do
    info' <- unsafeManagedPtrGetPtr info
    result <- g_dbus_annotation_info_ref info'
    checkUnexpectedReturnNULL "dBusAnnotationInfoRef" result
    result' <- (wrapBoxed DBusAnnotationInfo) result
    touchManagedPtr info
    return result'

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

#endif

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

foreign import ccall "g_dbus_annotation_info_unref" g_dbus_annotation_info_unref :: 
    Ptr DBusAnnotationInfo ->               -- info : TInterface (Name {namespace = "Gio", name = "DBusAnnotationInfo"})
    IO ()

{- |
If /@info@/ is statically allocated, does nothing. Otherwise decreases
the reference count of /@info@/. When its reference count drops to 0,
the memory used is freed.

@since 2.26
-}
dBusAnnotationInfoUnref ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    DBusAnnotationInfo
    {- ^ /@info@/: A 'GI.Gio.Structs.DBusAnnotationInfo.DBusAnnotationInfo'. -}
    -> m ()
dBusAnnotationInfoUnref info = liftIO $ do
    info' <- unsafeManagedPtrGetPtr info
    g_dbus_annotation_info_unref info'
    touchManagedPtr info
    return ()

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

#endif

-- method DBusAnnotationInfo::lookup
-- method type : MemberFunction
-- Args : [Arg {argCName = "annotations", argType = TCArray True (-1) (-1) (TInterface (Name {namespace = "Gio", name = "DBusAnnotationInfo"})), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "A %NULL-terminated array of annotations or %NULL.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The name of the annotation to look up.", 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 "g_dbus_annotation_info_lookup" g_dbus_annotation_info_lookup :: 
    Ptr (Ptr DBusAnnotationInfo) ->         -- annotations : TCArray True (-1) (-1) (TInterface (Name {namespace = "Gio", name = "DBusAnnotationInfo"}))
    CString ->                              -- name : TBasicType TUTF8
    IO CString

{- |
Looks up the value of an annotation.

The cost of this function is O(n) in number of annotations.

@since 2.26
-}
dBusAnnotationInfoLookup ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Maybe ([DBusAnnotationInfo])
    {- ^ /@annotations@/: A 'Nothing'-terminated array of annotations or 'Nothing'. -}
    -> T.Text
    {- ^ /@name@/: The name of the annotation to look up. -}
    -> m T.Text
    {- ^ __Returns:__ The value or 'Nothing' if not found. Do not free, it is owned by /@annotations@/. -}
dBusAnnotationInfoLookup annotations name = liftIO $ do
    maybeAnnotations <- case annotations of
        Nothing -> return nullPtr
        Just jAnnotations -> do
            jAnnotations' <- mapM unsafeManagedPtrGetPtr jAnnotations
            jAnnotations'' <- packZeroTerminatedPtrArray jAnnotations'
            return jAnnotations''
    name' <- textToCString name
    result <- g_dbus_annotation_info_lookup maybeAnnotations name'
    checkUnexpectedReturnNULL "dBusAnnotationInfoLookup" result
    result' <- cstringToText result
    whenJust annotations (mapM_ touchManagedPtr)
    freeMem maybeAnnotations
    freeMem name'
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type family ResolveDBusAnnotationInfoMethod (t :: Symbol) (o :: *) :: * where
    ResolveDBusAnnotationInfoMethod "ref" o = DBusAnnotationInfoRefMethodInfo
    ResolveDBusAnnotationInfoMethod "unref" o = DBusAnnotationInfoUnrefMethodInfo
    ResolveDBusAnnotationInfoMethod l o = O.MethodResolutionFailed l o

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

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