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

The class of an enumeration type holds information about its
possible values.
-}

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

module GI.GObject.Structs.EnumClass
    (

-- * Exported types
    EnumClass(..)                           ,
    newZeroEnumClass                        ,
    noEnumClass                             ,


 -- * Properties
-- ** gTypeClass #attr:gTypeClass#
{- | the parent class
-}
#if ENABLE_OVERLOADING
    enumClass_gTypeClass                    ,
#endif
    getEnumClassGTypeClass                  ,


-- ** maximum #attr:maximum#
{- | the largest possible value.
-}
#if ENABLE_OVERLOADING
    enumClass_maximum                       ,
#endif
    getEnumClassMaximum                     ,
    setEnumClassMaximum                     ,


-- ** minimum #attr:minimum#
{- | the smallest possible value.
-}
#if ENABLE_OVERLOADING
    enumClass_minimum                       ,
#endif
    getEnumClassMinimum                     ,
    setEnumClassMinimum                     ,


-- ** nValues #attr:nValues#
{- | the number of possible values.
-}
#if ENABLE_OVERLOADING
    enumClass_nValues                       ,
#endif
    getEnumClassNValues                     ,
    setEnumClassNValues                     ,


-- ** values #attr:values#
{- | an array of 'GI.GObject.Structs.EnumValue.EnumValue' structs describing the
 individual values.
-}
    clearEnumClassValues                    ,
#if ENABLE_OVERLOADING
    enumClass_values                        ,
#endif
    getEnumClassValues                      ,
    setEnumClassValues                      ,




    ) 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.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.GObject.Structs.EnumValue as GObject.EnumValue
import {-# SOURCE #-} qualified GI.GObject.Structs.TypeClass as GObject.TypeClass

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

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

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


-- | A convenience alias for `Nothing` :: `Maybe` `EnumClass`.
noEnumClass :: Maybe EnumClass
noEnumClass = Nothing

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

@
'Data.GI.Base.Attributes.get' enumClass #gTypeClass
@
-}
getEnumClassGTypeClass :: MonadIO m => EnumClass -> m GObject.TypeClass.TypeClass
getEnumClassGTypeClass s = liftIO $ withManagedPtr s $ \ptr -> do
    let val = ptr `plusPtr` 0 :: (Ptr GObject.TypeClass.TypeClass)
    val' <- (newPtr GObject.TypeClass.TypeClass) val
    return val'

#if ENABLE_OVERLOADING
data EnumClassGTypeClassFieldInfo
instance AttrInfo EnumClassGTypeClassFieldInfo where
    type AttrAllowedOps EnumClassGTypeClassFieldInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint EnumClassGTypeClassFieldInfo = (~) (Ptr GObject.TypeClass.TypeClass)
    type AttrBaseTypeConstraint EnumClassGTypeClassFieldInfo = (~) EnumClass
    type AttrGetType EnumClassGTypeClassFieldInfo = GObject.TypeClass.TypeClass
    type AttrLabel EnumClassGTypeClassFieldInfo = "g_type_class"
    type AttrOrigin EnumClassGTypeClassFieldInfo = EnumClass
    attrGet _ = getEnumClassGTypeClass
    attrSet _ = undefined
    attrConstruct = undefined
    attrClear _ = undefined

enumClass_gTypeClass :: AttrLabelProxy "gTypeClass"
enumClass_gTypeClass = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' enumClass #minimum
@
-}
getEnumClassMinimum :: MonadIO m => EnumClass -> m Int32
getEnumClassMinimum s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO Int32
    return val

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

@
'Data.GI.Base.Attributes.set' enumClass [ #minimum 'Data.GI.Base.Attributes.:=' value ]
@
-}
setEnumClassMinimum :: MonadIO m => EnumClass -> Int32 -> m ()
setEnumClassMinimum s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (val :: Int32)

#if ENABLE_OVERLOADING
data EnumClassMinimumFieldInfo
instance AttrInfo EnumClassMinimumFieldInfo where
    type AttrAllowedOps EnumClassMinimumFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint EnumClassMinimumFieldInfo = (~) Int32
    type AttrBaseTypeConstraint EnumClassMinimumFieldInfo = (~) EnumClass
    type AttrGetType EnumClassMinimumFieldInfo = Int32
    type AttrLabel EnumClassMinimumFieldInfo = "minimum"
    type AttrOrigin EnumClassMinimumFieldInfo = EnumClass
    attrGet _ = getEnumClassMinimum
    attrSet _ = setEnumClassMinimum
    attrConstruct = undefined
    attrClear _ = undefined

enumClass_minimum :: AttrLabelProxy "minimum"
enumClass_minimum = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' enumClass #maximum
@
-}
getEnumClassMaximum :: MonadIO m => EnumClass -> m Int32
getEnumClassMaximum s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 12) :: IO Int32
    return val

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

@
'Data.GI.Base.Attributes.set' enumClass [ #maximum 'Data.GI.Base.Attributes.:=' value ]
@
-}
setEnumClassMaximum :: MonadIO m => EnumClass -> Int32 -> m ()
setEnumClassMaximum s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 12) (val :: Int32)

#if ENABLE_OVERLOADING
data EnumClassMaximumFieldInfo
instance AttrInfo EnumClassMaximumFieldInfo where
    type AttrAllowedOps EnumClassMaximumFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint EnumClassMaximumFieldInfo = (~) Int32
    type AttrBaseTypeConstraint EnumClassMaximumFieldInfo = (~) EnumClass
    type AttrGetType EnumClassMaximumFieldInfo = Int32
    type AttrLabel EnumClassMaximumFieldInfo = "maximum"
    type AttrOrigin EnumClassMaximumFieldInfo = EnumClass
    attrGet _ = getEnumClassMaximum
    attrSet _ = setEnumClassMaximum
    attrConstruct = undefined
    attrClear _ = undefined

enumClass_maximum :: AttrLabelProxy "maximum"
enumClass_maximum = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' enumClass #nValues
@
-}
getEnumClassNValues :: MonadIO m => EnumClass -> m Word32
getEnumClassNValues s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 16) :: IO Word32
    return val

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

@
'Data.GI.Base.Attributes.set' enumClass [ #nValues 'Data.GI.Base.Attributes.:=' value ]
@
-}
setEnumClassNValues :: MonadIO m => EnumClass -> Word32 -> m ()
setEnumClassNValues s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 16) (val :: Word32)

#if ENABLE_OVERLOADING
data EnumClassNValuesFieldInfo
instance AttrInfo EnumClassNValuesFieldInfo where
    type AttrAllowedOps EnumClassNValuesFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint EnumClassNValuesFieldInfo = (~) Word32
    type AttrBaseTypeConstraint EnumClassNValuesFieldInfo = (~) EnumClass
    type AttrGetType EnumClassNValuesFieldInfo = Word32
    type AttrLabel EnumClassNValuesFieldInfo = "n_values"
    type AttrOrigin EnumClassNValuesFieldInfo = EnumClass
    attrGet _ = getEnumClassNValues
    attrSet _ = setEnumClassNValues
    attrConstruct = undefined
    attrClear _ = undefined

enumClass_nValues :: AttrLabelProxy "nValues"
enumClass_nValues = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' enumClass #values
@
-}
getEnumClassValues :: MonadIO m => EnumClass -> m (Maybe GObject.EnumValue.EnumValue)
getEnumClassValues s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 24) :: IO (Ptr GObject.EnumValue.EnumValue)
    result <- SP.convertIfNonNull val $ \val' -> do
        val'' <- (newPtr GObject.EnumValue.EnumValue) val'
        return val''
    return result

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

@
'Data.GI.Base.Attributes.set' enumClass [ #values 'Data.GI.Base.Attributes.:=' value ]
@
-}
setEnumClassValues :: MonadIO m => EnumClass -> Ptr GObject.EnumValue.EnumValue -> m ()
setEnumClassValues s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 24) (val :: Ptr GObject.EnumValue.EnumValue)

{- |
Set the value of the “@values@” 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' #values
@
-}
clearEnumClassValues :: MonadIO m => EnumClass -> m ()
clearEnumClassValues s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 24) (FP.nullPtr :: Ptr GObject.EnumValue.EnumValue)

#if ENABLE_OVERLOADING
data EnumClassValuesFieldInfo
instance AttrInfo EnumClassValuesFieldInfo where
    type AttrAllowedOps EnumClassValuesFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint EnumClassValuesFieldInfo = (~) (Ptr GObject.EnumValue.EnumValue)
    type AttrBaseTypeConstraint EnumClassValuesFieldInfo = (~) EnumClass
    type AttrGetType EnumClassValuesFieldInfo = Maybe GObject.EnumValue.EnumValue
    type AttrLabel EnumClassValuesFieldInfo = "values"
    type AttrOrigin EnumClassValuesFieldInfo = EnumClass
    attrGet _ = getEnumClassValues
    attrSet _ = setEnumClassValues
    attrConstruct = undefined
    attrClear _ = clearEnumClassValues

enumClass_values :: AttrLabelProxy "values"
enumClass_values = AttrLabelProxy

#endif



#if ENABLE_OVERLOADING
instance O.HasAttributeList EnumClass
type instance O.AttributeList EnumClass = EnumClassAttributeList
type EnumClassAttributeList = ('[ '("gTypeClass", EnumClassGTypeClassFieldInfo), '("minimum", EnumClassMinimumFieldInfo), '("maximum", EnumClassMaximumFieldInfo), '("nValues", EnumClassNValuesFieldInfo), '("values", EnumClassValuesFieldInfo)] :: [(Symbol, *)])
#endif

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

instance (info ~ ResolveEnumClassMethod t EnumClass, O.MethodInfo info EnumClass p) => OL.IsLabel t (EnumClass -> 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