{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- WpMetadataItem holds the subject, key, type and value of a metadata entry.

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

module GI.Wp.Structs.MetadataItem
    ( 

-- * Exported types
    MetadataItem(..)                        ,


 -- * Methods
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [ref]("GI.Wp.Structs.MetadataItem#g:method:ref"), [unref]("GI.Wp.Structs.MetadataItem#g:method:unref").
-- 
-- ==== Getters
-- [getKey]("GI.Wp.Structs.MetadataItem#g:method:getKey"), [getSubject]("GI.Wp.Structs.MetadataItem#g:method:getSubject"), [getValue]("GI.Wp.Structs.MetadataItem#g:method:getValue"), [getValueType]("GI.Wp.Structs.MetadataItem#g:method:getValueType").
-- 
-- ==== Setters
-- /None/.

#if defined(ENABLE_OVERLOADING)
    ResolveMetadataItemMethod               ,
#endif

-- ** getKey #method:getKey#

#if defined(ENABLE_OVERLOADING)
    MetadataItemGetKeyMethodInfo            ,
#endif
    metadataItemGetKey                      ,


-- ** getSubject #method:getSubject#

#if defined(ENABLE_OVERLOADING)
    MetadataItemGetSubjectMethodInfo        ,
#endif
    metadataItemGetSubject                  ,


-- ** getValue #method:getValue#

#if defined(ENABLE_OVERLOADING)
    MetadataItemGetValueMethodInfo          ,
#endif
    metadataItemGetValue                    ,


-- ** getValueType #method:getValueType#

#if defined(ENABLE_OVERLOADING)
    MetadataItemGetValueTypeMethodInfo      ,
#endif
    metadataItemGetValueType                ,


-- ** ref #method:ref#

#if defined(ENABLE_OVERLOADING)
    MetadataItemRefMethodInfo               ,
#endif
    metadataItemRef                         ,


-- ** unref #method:unref#

#if defined(ENABLE_OVERLOADING)
    MetadataItemUnrefMethodInfo             ,
#endif
    metadataItemUnref                       ,




    ) 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.GHashTable as B.GHT
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.Kind as DK
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 qualified Data.Word as DW
import qualified Data.Int as DI
import qualified System.Posix.Types as SPT
import qualified Foreign.C.Types as FCT

-- Workaround for https://gitlab.haskell.org/ghc/ghc/-/issues/23392
#if MIN_VERSION_base(4,18,0)

#else

#endif

-- | Memory-managed wrapper type.
newtype MetadataItem = MetadataItem (SP.ManagedPtr MetadataItem)
    deriving (Eq)

instance SP.ManagedPtrNewtype MetadataItem where
    toManagedPtr (MetadataItem p) = p

foreign import ccall "wp_metadata_item_get_type" c_wp_metadata_item_get_type :: 
    IO GType

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

instance B.Types.TypedObject MetadataItem where
    glibType = c_wp_metadata_item_get_type

instance B.Types.GBoxed MetadataItem

-- | Convert t'MetadataItem' 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 MetadataItem) where
    gvalueGType_ = c_wp_metadata_item_get_type
    gvalueSet_ gv P.Nothing = B.GValue.set_boxed gv (FP.nullPtr :: FP.Ptr MetadataItem)
    gvalueSet_ gv (P.Just obj) = B.ManagedPtr.withManagedPtr obj (B.GValue.set_boxed gv)
    gvalueGet_ gv = do
        ptr <- B.GValue.get_boxed gv :: IO (Ptr MetadataItem)
        if ptr /= FP.nullPtr
        then P.Just <$> B.ManagedPtr.newBoxed MetadataItem ptr
        else return P.Nothing
        
    


#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList MetadataItem
type instance O.AttributeList MetadataItem = MetadataItemAttributeList
type MetadataItemAttributeList = ('[ ] :: [(Symbol, DK.Type)])
#endif

-- method MetadataItem::get_key
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "self"
--           , argType =
--               TInterface Name { namespace = "Wp" , name = "MetadataItem" }
--           , argCType = Just "WpMetadataItem*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "the item held by the GValue that was returned from the WpIterator of wp_metadata_new_iterator()"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "wp_metadata_item_get_key" wp_metadata_item_get_key :: 
    Ptr MetadataItem ->                     -- self : TInterface (Name {namespace = "Wp", name = "MetadataItem"})
    IO CString

-- | Gets the key from a metadata item.
-- 
-- /Since: 0.5.0/
metadataItemGetKey ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    MetadataItem
    -- ^ /@self@/: the item held by the GValue that was returned from the WpIterator of 'GI.Wp.Objects.Metadata.metadataNewIterator'
    -> m T.Text
    -- ^ __Returns:__ the metadata key of the /@item@/
metadataItemGetKey self = liftIO $ do
    self' <- unsafeManagedPtrGetPtr self
    result <- wp_metadata_item_get_key self'
    checkUnexpectedReturnNULL "metadataItemGetKey" result
    result' <- cstringToText result
    touchManagedPtr self
    return result'

#if defined(ENABLE_OVERLOADING)
data MetadataItemGetKeyMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.OverloadedMethod MetadataItemGetKeyMethodInfo MetadataItem signature where
    overloadedMethod = metadataItemGetKey

instance O.OverloadedMethodInfo MetadataItemGetKeyMethodInfo MetadataItem where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Wp.Structs.MetadataItem.metadataItemGetKey",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-wireplumber-0.5.14.2/docs/GI-Wp-Structs-MetadataItem.html#v:metadataItemGetKey"
        })


#endif

-- method MetadataItem::get_subject
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "self"
--           , argType =
--               TInterface Name { namespace = "Wp" , name = "MetadataItem" }
--           , argCType = Just "WpMetadataItem*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "the item held by the GValue that was returned from the WpIterator of wp_metadata_new_iterator()"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUInt32)
-- throws : False
-- Skip return : False

foreign import ccall "wp_metadata_item_get_subject" wp_metadata_item_get_subject :: 
    Ptr MetadataItem ->                     -- self : TInterface (Name {namespace = "Wp", name = "MetadataItem"})
    IO Word32

-- | Gets the subject from a metadata item.
-- 
-- /Since: 0.5.0/
metadataItemGetSubject ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    MetadataItem
    -- ^ /@self@/: the item held by the GValue that was returned from the WpIterator of 'GI.Wp.Objects.Metadata.metadataNewIterator'
    -> m Word32
    -- ^ __Returns:__ the metadata subject of the /@item@/
metadataItemGetSubject self = liftIO $ do
    self' <- unsafeManagedPtrGetPtr self
    result <- wp_metadata_item_get_subject self'
    touchManagedPtr self
    return result

#if defined(ENABLE_OVERLOADING)
data MetadataItemGetSubjectMethodInfo
instance (signature ~ (m Word32), MonadIO m) => O.OverloadedMethod MetadataItemGetSubjectMethodInfo MetadataItem signature where
    overloadedMethod = metadataItemGetSubject

instance O.OverloadedMethodInfo MetadataItemGetSubjectMethodInfo MetadataItem where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Wp.Structs.MetadataItem.metadataItemGetSubject",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-wireplumber-0.5.14.2/docs/GI-Wp-Structs-MetadataItem.html#v:metadataItemGetSubject"
        })


#endif

-- method MetadataItem::get_value
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "self"
--           , argType =
--               TInterface Name { namespace = "Wp" , name = "MetadataItem" }
--           , argCType = Just "WpMetadataItem*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "the item held by the GValue that was returned from the WpIterator of wp_metadata_new_iterator()"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "wp_metadata_item_get_value" wp_metadata_item_get_value :: 
    Ptr MetadataItem ->                     -- self : TInterface (Name {namespace = "Wp", name = "MetadataItem"})
    IO CString

-- | Gets the value from a metadata item.
-- 
-- /Since: 0.5.0/
metadataItemGetValue ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    MetadataItem
    -- ^ /@self@/: the item held by the GValue that was returned from the WpIterator of 'GI.Wp.Objects.Metadata.metadataNewIterator'
    -> m T.Text
    -- ^ __Returns:__ the metadata value of the /@item@/
metadataItemGetValue self = liftIO $ do
    self' <- unsafeManagedPtrGetPtr self
    result <- wp_metadata_item_get_value self'
    checkUnexpectedReturnNULL "metadataItemGetValue" result
    result' <- cstringToText result
    touchManagedPtr self
    return result'

#if defined(ENABLE_OVERLOADING)
data MetadataItemGetValueMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.OverloadedMethod MetadataItemGetValueMethodInfo MetadataItem signature where
    overloadedMethod = metadataItemGetValue

instance O.OverloadedMethodInfo MetadataItemGetValueMethodInfo MetadataItem where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Wp.Structs.MetadataItem.metadataItemGetValue",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-wireplumber-0.5.14.2/docs/GI-Wp-Structs-MetadataItem.html#v:metadataItemGetValue"
        })


#endif

-- method MetadataItem::get_value_type
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "self"
--           , argType =
--               TInterface Name { namespace = "Wp" , name = "MetadataItem" }
--           , argCType = Just "WpMetadataItem*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "the item held by the GValue that was returned from the WpIterator of wp_metadata_new_iterator()"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "wp_metadata_item_get_value_type" wp_metadata_item_get_value_type :: 
    Ptr MetadataItem ->                     -- self : TInterface (Name {namespace = "Wp", name = "MetadataItem"})
    IO CString

-- | Gets the value type from a metadata item.
-- 
-- /Since: 0.5.0/
metadataItemGetValueType ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    MetadataItem
    -- ^ /@self@/: the item held by the GValue that was returned from the WpIterator of 'GI.Wp.Objects.Metadata.metadataNewIterator'
    -> m T.Text
    -- ^ __Returns:__ the metadata value type of the /@item@/
metadataItemGetValueType self = liftIO $ do
    self' <- unsafeManagedPtrGetPtr self
    result <- wp_metadata_item_get_value_type self'
    checkUnexpectedReturnNULL "metadataItemGetValueType" result
    result' <- cstringToText result
    touchManagedPtr self
    return result'

#if defined(ENABLE_OVERLOADING)
data MetadataItemGetValueTypeMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.OverloadedMethod MetadataItemGetValueTypeMethodInfo MetadataItem signature where
    overloadedMethod = metadataItemGetValueType

instance O.OverloadedMethodInfo MetadataItemGetValueTypeMethodInfo MetadataItem where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Wp.Structs.MetadataItem.metadataItemGetValueType",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-wireplumber-0.5.14.2/docs/GI-Wp-Structs-MetadataItem.html#v:metadataItemGetValueType"
        })


#endif

-- method MetadataItem::ref
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "self"
--           , argType =
--               TInterface Name { namespace = "Wp" , name = "MetadataItem" }
--           , argCType = Just "WpMetadataItem*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a metadata item object"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Wp" , name = "MetadataItem" })
-- throws : False
-- Skip return : False

foreign import ccall "wp_metadata_item_ref" wp_metadata_item_ref :: 
    Ptr MetadataItem ->                     -- self : TInterface (Name {namespace = "Wp", name = "MetadataItem"})
    IO (Ptr MetadataItem)

-- | Increases the reference count of a metadata item object.
-- 
-- /Since: 0.5.0/
metadataItemRef ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    MetadataItem
    -- ^ /@self@/: a metadata item object
    -> m MetadataItem
    -- ^ __Returns:__ /@self@/ with an additional reference count on it
metadataItemRef self = liftIO $ do
    self' <- unsafeManagedPtrGetPtr self
    result <- wp_metadata_item_ref self'
    checkUnexpectedReturnNULL "metadataItemRef" result
    result' <- (wrapBoxed MetadataItem) result
    touchManagedPtr self
    return result'

#if defined(ENABLE_OVERLOADING)
data MetadataItemRefMethodInfo
instance (signature ~ (m MetadataItem), MonadIO m) => O.OverloadedMethod MetadataItemRefMethodInfo MetadataItem signature where
    overloadedMethod = metadataItemRef

instance O.OverloadedMethodInfo MetadataItemRefMethodInfo MetadataItem where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Wp.Structs.MetadataItem.metadataItemRef",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-wireplumber-0.5.14.2/docs/GI-Wp-Structs-MetadataItem.html#v:metadataItemRef"
        })


#endif

-- method MetadataItem::unref
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "self"
--           , argType =
--               TInterface Name { namespace = "Wp" , name = "MetadataItem" }
--           , argCType = Just "WpMetadataItem*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a metadata item object"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "wp_metadata_item_unref" wp_metadata_item_unref :: 
    Ptr MetadataItem ->                     -- self : TInterface (Name {namespace = "Wp", name = "MetadataItem"})
    IO ()

-- | Decreases the reference count on /@self@/ and frees it when the ref count reaches zero.
-- 
-- /Since: 0.5.0/
metadataItemUnref ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    MetadataItem
    -- ^ /@self@/: a metadata item object
    -> m ()
metadataItemUnref self = liftIO $ do
    self' <- B.ManagedPtr.disownBoxed self
    wp_metadata_item_unref self'
    touchManagedPtr self
    return ()

#if defined(ENABLE_OVERLOADING)
data MetadataItemUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.OverloadedMethod MetadataItemUnrefMethodInfo MetadataItem signature where
    overloadedMethod = metadataItemUnref

instance O.OverloadedMethodInfo MetadataItemUnrefMethodInfo MetadataItem where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Wp.Structs.MetadataItem.metadataItemUnref",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-wireplumber-0.5.14.2/docs/GI-Wp-Structs-MetadataItem.html#v:metadataItemUnref"
        })


#endif

#if defined(ENABLE_OVERLOADING)
type family ResolveMetadataItemMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
    ResolveMetadataItemMethod "ref" o = MetadataItemRefMethodInfo
    ResolveMetadataItemMethod "unref" o = MetadataItemUnrefMethodInfo
    ResolveMetadataItemMethod "getKey" o = MetadataItemGetKeyMethodInfo
    ResolveMetadataItemMethod "getSubject" o = MetadataItemGetSubjectMethodInfo
    ResolveMetadataItemMethod "getValue" o = MetadataItemGetValueMethodInfo
    ResolveMetadataItemMethod "getValueType" o = MetadataItemGetValueTypeMethodInfo
    ResolveMetadataItemMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveMetadataItemMethod t MetadataItem, O.OverloadedMethod info MetadataItem p) => OL.IsLabel t (MetadataItem -> 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 ~ ResolveMetadataItemMethod t MetadataItem, O.OverloadedMethod info MetadataItem p, R.HasField t MetadataItem p) => R.HasField t MetadataItem p where
    getField = O.overloadedMethod @info

#endif

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

#endif


