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

A structure which contains a single flags value, its name, and its
nickname.
-}

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

module GI.GObject.Structs.FlagsValue
    (

-- * Exported types
    FlagsValue(..)                          ,
    newZeroFlagsValue                       ,
    noFlagsValue                            ,


 -- * Properties
-- ** value #attr:value#
{- | the flags value
-}
#if ENABLE_OVERLOADING
    flagsValue_value                        ,
#endif
    getFlagsValueValue                      ,
    setFlagsValueValue                      ,


-- ** valueName #attr:valueName#
{- | the name of the value
-}
    clearFlagsValueValueName                ,
#if ENABLE_OVERLOADING
    flagsValue_valueName                    ,
#endif
    getFlagsValueValueName                  ,
    setFlagsValueValueName                  ,


-- ** valueNick #attr:valueNick#
{- | the nickname of the value
-}
    clearFlagsValueValueNick                ,
#if ENABLE_OVERLOADING
    flagsValue_valueNick                    ,
#endif
    getFlagsValueValueNick                  ,
    setFlagsValueValueNick                  ,




    ) 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.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.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP


-- | Memory-managed wrapper type.
newtype FlagsValue = FlagsValue (ManagedPtr FlagsValue)
instance WrappedPtr FlagsValue where
    wrappedPtrCalloc = callocBytes 24
    wrappedPtrCopy = \p -> withManagedPtr p (copyBytes 24 >=> wrapPtr FlagsValue)
    wrappedPtrFree = Just ptr_to_g_free

-- | Construct a `FlagsValue` struct initialized to zero.
newZeroFlagsValue :: MonadIO m => m FlagsValue
newZeroFlagsValue = liftIO $ wrappedPtrCalloc >>= wrapPtr FlagsValue

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


-- | A convenience alias for `Nothing` :: `Maybe` `FlagsValue`.
noFlagsValue :: Maybe FlagsValue
noFlagsValue = Nothing

{- |
Get the value of the “@value@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' flagsValue #value
@
-}
getFlagsValueValue :: MonadIO m => FlagsValue -> m Word32
getFlagsValueValue s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO Word32
    return val

{- |
Set the value of the “@value@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' flagsValue [ #value 'Data.GI.Base.Attributes.:=' value ]
@
-}
setFlagsValueValue :: MonadIO m => FlagsValue -> Word32 -> m ()
setFlagsValueValue s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (val :: Word32)

#if ENABLE_OVERLOADING
data FlagsValueValueFieldInfo
instance AttrInfo FlagsValueValueFieldInfo where
    type AttrAllowedOps FlagsValueValueFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint FlagsValueValueFieldInfo = (~) Word32
    type AttrBaseTypeConstraint FlagsValueValueFieldInfo = (~) FlagsValue
    type AttrGetType FlagsValueValueFieldInfo = Word32
    type AttrLabel FlagsValueValueFieldInfo = "value"
    type AttrOrigin FlagsValueValueFieldInfo = FlagsValue
    attrGet _ = getFlagsValueValue
    attrSet _ = setFlagsValueValue
    attrConstruct = undefined
    attrClear _ = undefined

flagsValue_value :: AttrLabelProxy "value"
flagsValue_value = AttrLabelProxy

#endif


{- |
Get the value of the “@value_name@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' flagsValue #valueName
@
-}
getFlagsValueValueName :: MonadIO m => FlagsValue -> m (Maybe T.Text)
getFlagsValueValueName 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

{- |
Set the value of the “@value_name@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' flagsValue [ #valueName 'Data.GI.Base.Attributes.:=' value ]
@
-}
setFlagsValueValueName :: MonadIO m => FlagsValue -> CString -> m ()
setFlagsValueValueName s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (val :: CString)

{- |
Set the value of the “@value_name@” field to `Nothing`.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.clear' #valueName
@
-}
clearFlagsValueValueName :: MonadIO m => FlagsValue -> m ()
clearFlagsValueValueName s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (FP.nullPtr :: CString)

#if ENABLE_OVERLOADING
data FlagsValueValueNameFieldInfo
instance AttrInfo FlagsValueValueNameFieldInfo where
    type AttrAllowedOps FlagsValueValueNameFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint FlagsValueValueNameFieldInfo = (~) CString
    type AttrBaseTypeConstraint FlagsValueValueNameFieldInfo = (~) FlagsValue
    type AttrGetType FlagsValueValueNameFieldInfo = Maybe T.Text
    type AttrLabel FlagsValueValueNameFieldInfo = "value_name"
    type AttrOrigin FlagsValueValueNameFieldInfo = FlagsValue
    attrGet _ = getFlagsValueValueName
    attrSet _ = setFlagsValueValueName
    attrConstruct = undefined
    attrClear _ = clearFlagsValueValueName

flagsValue_valueName :: AttrLabelProxy "valueName"
flagsValue_valueName = AttrLabelProxy

#endif


{- |
Get the value of the “@value_nick@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' flagsValue #valueNick
@
-}
getFlagsValueValueNick :: MonadIO m => FlagsValue -> m (Maybe T.Text)
getFlagsValueValueNick 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

{- |
Set the value of the “@value_nick@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' flagsValue [ #valueNick 'Data.GI.Base.Attributes.:=' value ]
@
-}
setFlagsValueValueNick :: MonadIO m => FlagsValue -> CString -> m ()
setFlagsValueValueNick s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 16) (val :: CString)

{- |
Set the value of the “@value_nick@” field to `Nothing`.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.clear' #valueNick
@
-}
clearFlagsValueValueNick :: MonadIO m => FlagsValue -> m ()
clearFlagsValueValueNick s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 16) (FP.nullPtr :: CString)

#if ENABLE_OVERLOADING
data FlagsValueValueNickFieldInfo
instance AttrInfo FlagsValueValueNickFieldInfo where
    type AttrAllowedOps FlagsValueValueNickFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint FlagsValueValueNickFieldInfo = (~) CString
    type AttrBaseTypeConstraint FlagsValueValueNickFieldInfo = (~) FlagsValue
    type AttrGetType FlagsValueValueNickFieldInfo = Maybe T.Text
    type AttrLabel FlagsValueValueNickFieldInfo = "value_nick"
    type AttrOrigin FlagsValueValueNickFieldInfo = FlagsValue
    attrGet _ = getFlagsValueValueNick
    attrSet _ = setFlagsValueValueNick
    attrConstruct = undefined
    attrClear _ = clearFlagsValueValueNick

flagsValue_valueNick :: AttrLabelProxy "valueNick"
flagsValue_valueNick = AttrLabelProxy

#endif



#if ENABLE_OVERLOADING
instance O.HasAttributeList FlagsValue
type instance O.AttributeList FlagsValue = FlagsValueAttributeList
type FlagsValueAttributeList = ('[ '("value", FlagsValueValueFieldInfo), '("valueName", FlagsValueValueNameFieldInfo), '("valueNick", FlagsValueValueNickFieldInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
type family ResolveFlagsValueMethod (t :: Symbol) (o :: *) :: * where
    ResolveFlagsValueMethod l o = O.MethodResolutionFailed l o

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

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