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

module GI.Poppler.Structs.ActionAny
    ( 

-- * Exported types
    ActionAny(..)                           ,
    newZeroActionAny                        ,
    noActionAny                             ,


 -- * Properties
-- ** title #attr:title#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    actionAny_title                         ,
#endif
    clearActionAnyTitle                     ,
    getActionAnyTitle                       ,
    setActionAnyTitle                       ,


-- ** type #attr:type#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    actionAny_type                          ,
#endif
    getActionAnyType                        ,
    setActionAnyType                        ,




    ) 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 ActionAny = ActionAny (ManagedPtr ActionAny)
instance WrappedPtr ActionAny where
    wrappedPtrCalloc = callocBytes 16
    wrappedPtrCopy = \p -> withManagedPtr p (copyBytes 16 >=> wrapPtr ActionAny)
    wrappedPtrFree = Just ptr_to_g_free

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

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


noActionAny :: Maybe ActionAny
noActionAny = Nothing

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

setActionAnyType :: MonadIO m => ActionAny -> Poppler.Enums.ActionType -> m ()
setActionAnyType 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 ActionAnyTypeFieldInfo
instance AttrInfo ActionAnyTypeFieldInfo where
    type AttrAllowedOps ActionAnyTypeFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint ActionAnyTypeFieldInfo = (~) Poppler.Enums.ActionType
    type AttrBaseTypeConstraint ActionAnyTypeFieldInfo = (~) ActionAny
    type AttrGetType ActionAnyTypeFieldInfo = Poppler.Enums.ActionType
    type AttrLabel ActionAnyTypeFieldInfo = "type"
    type AttrOrigin ActionAnyTypeFieldInfo = ActionAny
    attrGet _ = getActionAnyType
    attrSet _ = setActionAnyType
    attrConstruct = undefined
    attrClear _ = undefined

actionAny_type :: AttrLabelProxy "type"
actionAny_type = AttrLabelProxy

#endif


getActionAnyTitle :: MonadIO m => ActionAny -> m (Maybe T.Text)
getActionAnyTitle 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

setActionAnyTitle :: MonadIO m => ActionAny -> CString -> m ()
setActionAnyTitle s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (val :: CString)

clearActionAnyTitle :: MonadIO m => ActionAny -> m ()
clearActionAnyTitle s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (FP.nullPtr :: CString)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data ActionAnyTitleFieldInfo
instance AttrInfo ActionAnyTitleFieldInfo where
    type AttrAllowedOps ActionAnyTitleFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint ActionAnyTitleFieldInfo = (~) CString
    type AttrBaseTypeConstraint ActionAnyTitleFieldInfo = (~) ActionAny
    type AttrGetType ActionAnyTitleFieldInfo = Maybe T.Text
    type AttrLabel ActionAnyTitleFieldInfo = "title"
    type AttrOrigin ActionAnyTitleFieldInfo = ActionAny
    attrGet _ = getActionAnyTitle
    attrSet _ = setActionAnyTitle
    attrConstruct = undefined
    attrClear _ = clearActionAnyTitle

actionAny_title :: AttrLabelProxy "title"
actionAny_title = AttrLabelProxy

#endif



#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
instance O.HasAttributeList ActionAny
type instance O.AttributeList ActionAny = ActionAnyAttributeList
type ActionAnyAttributeList = ('[ '("type", ActionAnyTypeFieldInfo), '("title", ActionAnyTitleFieldInfo)] :: [(Symbol, *)])
#endif

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

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

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