{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- WpSettingsItem holds the key and value of a setting

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

module GI.Wp.Structs.SettingsItem
    ( 

-- * Exported types
    SettingsItem(..)                        ,


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

#if defined(ENABLE_OVERLOADING)
    ResolveSettingsItemMethod               ,
#endif

-- ** getKey #method:getKey#

#if defined(ENABLE_OVERLOADING)
    SettingsItemGetKeyMethodInfo            ,
#endif
    settingsItemGetKey                      ,


-- ** getValue #method:getValue#

#if defined(ENABLE_OVERLOADING)
    SettingsItemGetValueMethodInfo          ,
#endif
    settingsItemGetValue                    ,


-- ** ref #method:ref#

#if defined(ENABLE_OVERLOADING)
    SettingsItemRefMethodInfo               ,
#endif
    settingsItemRef                         ,


-- ** unref #method:unref#

#if defined(ENABLE_OVERLOADING)
    SettingsItemUnrefMethodInfo             ,
#endif
    settingsItemUnref                       ,




    ) 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)
import qualified GI.Wp.Callbacks as Wp.Callbacks
import {-# SOURCE #-} qualified GI.Wp.Structs.Iterator as Wp.Iterator
import {-# SOURCE #-} qualified GI.Wp.Structs.IteratorMethods as Wp.IteratorMethods
import {-# SOURCE #-} qualified GI.Wp.Structs.SpaJson as Wp.SpaJson

#else
import {-# SOURCE #-} qualified GI.Wp.Structs.SpaJson as Wp.SpaJson

#endif

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

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

foreign import ccall "wp_settings_item_get_type" c_wp_settings_item_get_type :: 
    IO GType

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

instance B.Types.TypedObject SettingsItem where
    glibType = c_wp_settings_item_get_type

instance B.Types.GBoxed SettingsItem

-- | Convert t'SettingsItem' 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 SettingsItem) where
    gvalueGType_ = c_wp_settings_item_get_type
    gvalueSet_ gv P.Nothing = B.GValue.set_boxed gv (FP.nullPtr :: FP.Ptr SettingsItem)
    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 SettingsItem)
        if ptr /= FP.nullPtr
        then P.Just <$> B.ManagedPtr.newBoxed SettingsItem ptr
        else return P.Nothing
        
    


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

-- method SettingsItem::get_key
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "self"
--           , argType =
--               TInterface Name { namespace = "Wp" , name = "SettingsItem" }
--           , argCType = Just "WpSettingsItem*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "the item held by the GValue that was returned from the WpIterator of wp_settings_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_settings_item_get_key" wp_settings_item_get_key :: 
    Ptr SettingsItem ->                     -- self : TInterface (Name {namespace = "Wp", name = "SettingsItem"})
    IO CString

-- | Gets the key from a settings item.
settingsItemGetKey ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    SettingsItem
    -- ^ /@self@/: the item held by the GValue that was returned from the WpIterator of 'GI.Wp.Objects.Settings.settingsNewIterator'
    -> m T.Text
    -- ^ __Returns:__ the settings key of the /@item@/
settingsItemGetKey self = liftIO $ do
    self' <- unsafeManagedPtrGetPtr self
    result <- wp_settings_item_get_key self'
    checkUnexpectedReturnNULL "settingsItemGetKey" result
    result' <- cstringToText result
    touchManagedPtr self
    return result'

#if defined(ENABLE_OVERLOADING)
data SettingsItemGetKeyMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.OverloadedMethod SettingsItemGetKeyMethodInfo SettingsItem signature where
    overloadedMethod = settingsItemGetKey

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


#endif

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

foreign import ccall "wp_settings_item_get_value" wp_settings_item_get_value :: 
    Ptr SettingsItem ->                     -- self : TInterface (Name {namespace = "Wp", name = "SettingsItem"})
    IO (Ptr Wp.SpaJson.SpaJson)

-- | Gets the value from a settings item.
settingsItemGetValue ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    SettingsItem
    -- ^ /@self@/: the item held by the GValue that was returned from the WpIterator of 'GI.Wp.Objects.Settings.settingsNewIterator'
    -> m Wp.SpaJson.SpaJson
    -- ^ __Returns:__ the settings value of the /@item@/
settingsItemGetValue self = liftIO $ do
    self' <- unsafeManagedPtrGetPtr self
    result <- wp_settings_item_get_value self'
    checkUnexpectedReturnNULL "settingsItemGetValue" result
    result' <- (wrapBoxed Wp.SpaJson.SpaJson) result
    touchManagedPtr self
    return result'

#if defined(ENABLE_OVERLOADING)
data SettingsItemGetValueMethodInfo
instance (signature ~ (m Wp.SpaJson.SpaJson), MonadIO m) => O.OverloadedMethod SettingsItemGetValueMethodInfo SettingsItem signature where
    overloadedMethod = settingsItemGetValue

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


#endif

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

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

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

#if defined(ENABLE_OVERLOADING)
data SettingsItemRefMethodInfo
instance (signature ~ (m SettingsItem), MonadIO m) => O.OverloadedMethod SettingsItemRefMethodInfo SettingsItem signature where
    overloadedMethod = settingsItemRef

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


#endif

-- method SettingsItem::unref
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "self"
--           , argType =
--               TInterface Name { namespace = "Wp" , name = "SettingsItem" }
--           , argCType = Just "WpSettingsItem*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a settings 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_settings_item_unref" wp_settings_item_unref :: 
    Ptr SettingsItem ->                     -- self : TInterface (Name {namespace = "Wp", name = "SettingsItem"})
    IO ()

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

#if defined(ENABLE_OVERLOADING)
data SettingsItemUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.OverloadedMethod SettingsItemUnrefMethodInfo SettingsItem signature where
    overloadedMethod = settingsItemUnref

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


#endif

#if defined(ENABLE_OVERLOADING)
type family ResolveSettingsItemMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
    ResolveSettingsItemMethod "ref" o = SettingsItemRefMethodInfo
    ResolveSettingsItemMethod "unref" o = SettingsItemUnrefMethodInfo
    ResolveSettingsItemMethod "getKey" o = SettingsItemGetKeyMethodInfo
    ResolveSettingsItemMethod "getValue" o = SettingsItemGetValueMethodInfo
    ResolveSettingsItemMethod l o = O.MethodResolutionFailed l o

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

#endif

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

#endif


