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

Action to perform over a list of layers
-}

module GI.Poppler.Structs.ActionLayer
    ( 

-- * Exported types
    ActionLayer(..)                         ,
    newZeroActionLayer                      ,
    noActionLayer                           ,


 -- * Properties
-- ** action #attr:action#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    actionLayer_action                      ,
#endif
    getActionLayerAction                    ,
    setActionLayerAction                    ,


-- ** layers #attr:layers#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    actionLayer_layers                      ,
#endif
    clearActionLayerLayers                  ,
    getActionLayerLayers                    ,
    setActionLayerLayers                    ,




    ) 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.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

import {-# SOURCE #-} qualified GI.Poppler.Enums as Poppler.Enums

newtype ActionLayer = ActionLayer (ManagedPtr ActionLayer)
instance WrappedPtr ActionLayer where
    wrappedPtrCalloc = callocBytes 16
    wrappedPtrCopy = \p -> withManagedPtr p (copyBytes 16 >=> wrapPtr ActionLayer)
    wrappedPtrFree = Just ptr_to_g_free

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

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


noActionLayer :: Maybe ActionLayer
noActionLayer = Nothing

getActionLayerAction :: MonadIO m => ActionLayer -> m Poppler.Enums.ActionLayerAction
getActionLayerAction s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO CUInt
    let val' = (toEnum . fromIntegral) val
    return val'

setActionLayerAction :: MonadIO m => ActionLayer -> Poppler.Enums.ActionLayerAction -> m ()
setActionLayerAction s val = liftIO $ withManagedPtr s $ \ptr -> do
    let val' = (fromIntegral . fromEnum) val
    poke (ptr `plusPtr` 0) (val' :: CUInt)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data ActionLayerActionFieldInfo
instance AttrInfo ActionLayerActionFieldInfo where
    type AttrAllowedOps ActionLayerActionFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint ActionLayerActionFieldInfo = (~) Poppler.Enums.ActionLayerAction
    type AttrBaseTypeConstraint ActionLayerActionFieldInfo = (~) ActionLayer
    type AttrGetType ActionLayerActionFieldInfo = Poppler.Enums.ActionLayerAction
    type AttrLabel ActionLayerActionFieldInfo = "action"
    type AttrOrigin ActionLayerActionFieldInfo = ActionLayer
    attrGet _ = getActionLayerAction
    attrSet _ = setActionLayerAction
    attrConstruct = undefined
    attrClear _ = undefined

actionLayer_action :: AttrLabelProxy "action"
actionLayer_action = AttrLabelProxy

#endif


getActionLayerLayers :: MonadIO m => ActionLayer -> m ([Ptr ()])
getActionLayerLayers s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO (Ptr (GList (Ptr ())))
    val' <- unpackGList val
    return val'

setActionLayerLayers :: MonadIO m => ActionLayer -> Ptr (GList (Ptr ())) -> m ()
setActionLayerLayers s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (val :: Ptr (GList (Ptr ())))

clearActionLayerLayers :: MonadIO m => ActionLayer -> m ()
clearActionLayerLayers s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (FP.nullPtr :: Ptr (GList (Ptr ())))

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data ActionLayerLayersFieldInfo
instance AttrInfo ActionLayerLayersFieldInfo where
    type AttrAllowedOps ActionLayerLayersFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint ActionLayerLayersFieldInfo = (~) (Ptr (GList (Ptr ())))
    type AttrBaseTypeConstraint ActionLayerLayersFieldInfo = (~) ActionLayer
    type AttrGetType ActionLayerLayersFieldInfo = [Ptr ()]
    type AttrLabel ActionLayerLayersFieldInfo = "layers"
    type AttrOrigin ActionLayerLayersFieldInfo = ActionLayer
    attrGet _ = getActionLayerLayers
    attrSet _ = setActionLayerLayers
    attrConstruct = undefined
    attrClear _ = clearActionLayerLayers

actionLayer_layers :: AttrLabelProxy "layers"
actionLayer_layers = AttrLabelProxy

#endif



#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
instance O.HasAttributeList ActionLayer
type instance O.AttributeList ActionLayer = ActionLayerAttributeList
type ActionLayerAttributeList = ('[ '("action", ActionLayerActionFieldInfo), '("layers", ActionLayerLayersFieldInfo)] :: [(Symbol, *)])
#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type family ResolveActionLayerMethod (t :: Symbol) (o :: *) :: * where
    ResolveActionLayerMethod l o = O.MethodResolutionFailed l o

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

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