{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- Represents a git configuration entry.

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

module GI.Ggit.Structs.ConfigEntry
    (

-- * Exported types
    ConfigEntry(..)                         ,
    noConfigEntry                           ,


 -- * Methods
-- ** Overloaded methods #method:Overloaded methods#

#if defined(ENABLE_OVERLOADING)
    ResolveConfigEntryMethod                ,
#endif


-- ** getLevel #method:getLevel#

#if defined(ENABLE_OVERLOADING)
    ConfigEntryGetLevelMethodInfo           ,
#endif
    configEntryGetLevel                     ,


-- ** getName #method:getName#

#if defined(ENABLE_OVERLOADING)
    ConfigEntryGetNameMethodInfo            ,
#endif
    configEntryGetName                      ,


-- ** getValue #method:getValue#

#if defined(ENABLE_OVERLOADING)
    ConfigEntryGetValueMethodInfo           ,
#endif
    configEntryGetValue                     ,


-- ** ref #method:ref#

#if defined(ENABLE_OVERLOADING)
    ConfigEntryRefMethodInfo                ,
#endif
    configEntryRef                          ,


-- ** unref #method:unref#

#if defined(ENABLE_OVERLOADING)
    ConfigEntryUnrefMethodInfo              ,
#endif
    configEntryUnref                        ,




    ) 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.GI.Base.Signals as B.Signals
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 {-# SOURCE #-} qualified GI.Ggit.Enums as Ggit.Enums

-- | Memory-managed wrapper type.
newtype ConfigEntry = ConfigEntry (ManagedPtr ConfigEntry)
    deriving (Eq)
foreign import ccall "ggit_config_entry_get_type" c_ggit_config_entry_get_type ::
    IO GType

instance BoxedObject ConfigEntry where
    boxedType _ = c_ggit_config_entry_get_type

-- | Convert 'ConfigEntry' to and from 'Data.GI.Base.GValue.GValue' with 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue ConfigEntry where
    toGValue o = do
        gtype <- c_ggit_config_entry_get_type
        B.ManagedPtr.withManagedPtr o (B.GValue.buildGValue gtype B.GValue.set_boxed)

    fromGValue gv = do
        ptr <- B.GValue.get_boxed gv :: IO (Ptr ConfigEntry)
        B.ManagedPtr.newBoxed ConfigEntry ptr



-- | A convenience alias for `Nothing` :: `Maybe` `ConfigEntry`.
noConfigEntry :: Maybe ConfigEntry
noConfigEntry = Nothing


#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList ConfigEntry
type instance O.AttributeList ConfigEntry = ConfigEntryAttributeList
type ConfigEntryAttributeList = ('[ ] :: [(Symbol, *)])
#endif

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

foreign import ccall "ggit_config_entry_get_level" ggit_config_entry_get_level ::
    Ptr ConfigEntry ->                      -- entry : TInterface (Name {namespace = "Ggit", name = "ConfigEntry"})
    IO CInt

-- | Gets the t'GI.Ggit.Enums.ConfigLevel' of /@entry@/.
configEntryGetLevel ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ConfigEntry
    -- ^ /@entry@/: a t'GI.Ggit.Structs.ConfigEntry.ConfigEntry'.
    -> m Ggit.Enums.ConfigLevel
    -- ^ __Returns:__ the t'GI.Ggit.Enums.ConfigLevel' of /@entry@/.
configEntryGetLevel entry = liftIO $ do
    entry' <- unsafeManagedPtrGetPtr entry
    result <- ggit_config_entry_get_level entry'
    let result' = (toEnum . fromIntegral) result
    touchManagedPtr entry
    return result'

#if defined(ENABLE_OVERLOADING)
data ConfigEntryGetLevelMethodInfo
instance (signature ~ (m Ggit.Enums.ConfigLevel), MonadIO m) => O.MethodInfo ConfigEntryGetLevelMethodInfo ConfigEntry signature where
    overloadedMethod = configEntryGetLevel

#endif

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

-- | Gets the name of /@entry@/.
configEntryGetName ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ConfigEntry
    -- ^ /@entry@/: a t'GI.Ggit.Structs.ConfigEntry.ConfigEntry'.
    -> m (Maybe T.Text)
    -- ^ __Returns:__ the name of /@entry@/ or 'P.Nothing'.
configEntryGetName entry = liftIO $ do
    entry' <- unsafeManagedPtrGetPtr entry
    result <- ggit_config_entry_get_name entry'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToText result'
        return result''
    touchManagedPtr entry
    return maybeResult

#if defined(ENABLE_OVERLOADING)
data ConfigEntryGetNameMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m) => O.MethodInfo ConfigEntryGetNameMethodInfo ConfigEntry signature where
    overloadedMethod = configEntryGetName

#endif

-- method ConfigEntry::get_value
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "entry"
--           , argType =
--               TInterface Name { namespace = "Ggit" , name = "ConfigEntry" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GgitConfigEntry."
--                 , 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_config_entry_get_value" ggit_config_entry_get_value ::
    Ptr ConfigEntry ->                      -- entry : TInterface (Name {namespace = "Ggit", name = "ConfigEntry"})
    IO CString

-- | Gets the value of /@entry@/.
configEntryGetValue ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ConfigEntry
    -- ^ /@entry@/: a t'GI.Ggit.Structs.ConfigEntry.ConfigEntry'.
    -> m (Maybe T.Text)
    -- ^ __Returns:__ the value of /@entry@/ or 'P.Nothing'.
configEntryGetValue entry = liftIO $ do
    entry' <- unsafeManagedPtrGetPtr entry
    result <- ggit_config_entry_get_value entry'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToText result'
        return result''
    touchManagedPtr entry
    return maybeResult

#if defined(ENABLE_OVERLOADING)
data ConfigEntryGetValueMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m) => O.MethodInfo ConfigEntryGetValueMethodInfo ConfigEntry signature where
    overloadedMethod = configEntryGetValue

#endif

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

foreign import ccall "ggit_config_entry_ref" ggit_config_entry_ref ::
    Ptr ConfigEntry ->                      -- entry : TInterface (Name {namespace = "Ggit", name = "ConfigEntry"})
    IO (Ptr ConfigEntry)

-- | Atomically increments the reference count of /@entry@/ by one.
-- This function is MT-safe and may be called from any thread.
configEntryRef ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ConfigEntry
    -- ^ /@entry@/: a t'GI.Ggit.Structs.ConfigEntry.ConfigEntry'.
    -> m (Maybe ConfigEntry)
    -- ^ __Returns:__ a t'GI.Ggit.Structs.ConfigEntry.ConfigEntry' or 'P.Nothing'.
configEntryRef entry = liftIO $ do
    entry' <- unsafeManagedPtrGetPtr entry
    result <- ggit_config_entry_ref entry'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (newBoxed ConfigEntry) result'
        return result''
    touchManagedPtr entry
    return maybeResult

#if defined(ENABLE_OVERLOADING)
data ConfigEntryRefMethodInfo
instance (signature ~ (m (Maybe ConfigEntry)), MonadIO m) => O.MethodInfo ConfigEntryRefMethodInfo ConfigEntry signature where
    overloadedMethod = configEntryRef

#endif

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

foreign import ccall "ggit_config_entry_unref" ggit_config_entry_unref ::
    Ptr ConfigEntry ->                      -- entry : TInterface (Name {namespace = "Ggit", name = "ConfigEntry"})
    IO ()

-- | Atomically decrements the reference count of /@entry@/ by one.
-- If the reference count drops to 0, /@entry@/ is freed.
configEntryUnref ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ConfigEntry
    -- ^ /@entry@/: a t'GI.Ggit.Structs.ConfigEntry.ConfigEntry'.
    -> m ()
configEntryUnref entry = liftIO $ do
    entry' <- unsafeManagedPtrGetPtr entry
    ggit_config_entry_unref entry'
    touchManagedPtr entry
    return ()

#if defined(ENABLE_OVERLOADING)
data ConfigEntryUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo ConfigEntryUnrefMethodInfo ConfigEntry signature where
    overloadedMethod = configEntryUnref

#endif

#if defined(ENABLE_OVERLOADING)
type family ResolveConfigEntryMethod (t :: Symbol) (o :: *) :: * where
    ResolveConfigEntryMethod "ref" o = ConfigEntryRefMethodInfo
    ResolveConfigEntryMethod "unref" o = ConfigEntryUnrefMethodInfo
    ResolveConfigEntryMethod "getLevel" o = ConfigEntryGetLevelMethodInfo
    ResolveConfigEntryMethod "getName" o = ConfigEntryGetNameMethodInfo
    ResolveConfigEntryMethod "getValue" o = ConfigEntryGetValueMethodInfo
    ResolveConfigEntryMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveConfigEntryMethod t ConfigEntry, O.MethodInfo info ConfigEntry p) => OL.IsLabel t (ConfigEntry -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#endif