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

    The 'GI.Pango.Structs.Attribute.Attribute' structure represents the common portions of all
    attributes. Particular types of attributes include this structure
    as their initial portion. The common portion of the attribute holds
    the range to which the value in the type-specific part of the attribute
    applies and should be initialized using 'GI.Pango.Structs.Attribute.attributeInit'.
    By default an attribute will have an all-inclusive range of [0,@/G_MAXUINT/@].
    -}

    #define ENABLE_OVERLOADING \
           (!defined(__HADDOCK_VERSION__))

    module GI.Pango.Structs.Attribute
        (

    -- * Exported types
        Attribute(..)                           ,
        noAttribute                             ,

     -- * Methods
    -- ** destroy #method:destroy#

    #if ENABLE_OVERLOADING
        AttributeDestroyMethodInfo              ,
    #endif
        attributeDestroy                        ,

    -- ** equal #method:equal#

    #if ENABLE_OVERLOADING
        AttributeEqualMethodInfo                ,
    #endif
        attributeEqual                          ,

    -- ** init #method:init#

    #if ENABLE_OVERLOADING
        AttributeInitMethodInfo                 ,
    #endif
        attributeInit                           ,

     -- * Properties
    -- ** endIndex #attr:endIndex#
    {- | end index of the range (in bytes). The character at this index
    is not included in the range.
    -}
    #if ENABLE_OVERLOADING
        attribute_endIndex                      ,
    #endif
        getAttributeEndIndex                    ,
        setAttributeEndIndex                    ,

    -- ** klass #attr:klass#
    {- | the class structure holding information about the type of the attribute
    -}
    #if ENABLE_OVERLOADING
        attribute_klass                         ,
    #endif
        clearAttributeKlass                     ,
        getAttributeKlass                       ,
        setAttributeKlass                       ,

    -- ** startIndex #attr:startIndex#
    {- | the start index of the range (in bytes).
    -}
    #if ENABLE_OVERLOADING
        attribute_startIndex                    ,
    #endif
        getAttributeStartIndex                  ,
        setAttributeStartIndex                  ,

        ) 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

    import {-# SOURCE #-} qualified GI.Pango.Structs.AttrClass as Pango.AttrClass

    -- | Memory-managed wrapper type.
    newtype Attribute = Attribute (ManagedPtr Attribute)
    foreign import ccall "pango_attribute_copy" _Attribute_copy_pango_attribute_copy :: Ptr a -> IO (Ptr a)

    foreign import ccall "&pango_attribute_destroy" _Attribute_free_pango_attribute_destroy :: FunPtr (Ptr a -> IO ())

    instance WrappedPtr Attribute where
        wrappedPtrCalloc = error "calloc not permitted for Attribute"
        wrappedPtrCopy = \p -> withManagedPtr p (_Attribute_copy_pango_attribute_copy >=> wrapPtr Attribute)
        wrappedPtrFree = Just _Attribute_free_pango_attribute_destroy

    -- | A convenience alias for `Nothing` :: `Maybe` `Attribute`.
    noAttribute :: Maybe Attribute
    noAttribute = Nothing

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

    @
    'Data.GI.Base.Attributes.get' attribute #klass
    @
    -}
    getAttributeKlass :: MonadIO m => Attribute -> m (Maybe Pango.AttrClass.AttrClass)
    getAttributeKlass s = liftIO $ withManagedPtr s $ \ptr -> do
        val <- peek (ptr `plusPtr` 0) :: IO (Ptr Pango.AttrClass.AttrClass)
        result <- SP.convertIfNonNull val $ \val' -> do
            val'' <- (newPtr Pango.AttrClass.AttrClass) val'
            return val''
        return result

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

    @
    'Data.GI.Base.Attributes.set' attribute [ #klass 'Data.GI.Base.Attributes.:=' value ]
    @
    -}
    setAttributeKlass :: MonadIO m => Attribute -> Ptr Pango.AttrClass.AttrClass -> m ()
    setAttributeKlass s val = liftIO $ withManagedPtr s $ \ptr -> do
        poke (ptr `plusPtr` 0) (val :: Ptr Pango.AttrClass.AttrClass)

    {- |
    Set the value of the “@klass@” 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' #klass
    @
    -}
    clearAttributeKlass :: MonadIO m => Attribute -> m ()
    clearAttributeKlass s = liftIO $ withManagedPtr s $ \ptr -> do
        poke (ptr `plusPtr` 0) (FP.nullPtr :: Ptr Pango.AttrClass.AttrClass)

    #if ENABLE_OVERLOADING
    data AttributeKlassFieldInfo
    instance AttrInfo AttributeKlassFieldInfo where
        type AttrAllowedOps AttributeKlassFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
        type AttrSetTypeConstraint AttributeKlassFieldInfo = (~) (Ptr Pango.AttrClass.AttrClass)
        type AttrBaseTypeConstraint AttributeKlassFieldInfo = (~) Attribute
        type AttrGetType AttributeKlassFieldInfo = Maybe Pango.AttrClass.AttrClass
        type AttrLabel AttributeKlassFieldInfo = "klass"
        type AttrOrigin AttributeKlassFieldInfo = Attribute
        attrGet _ = getAttributeKlass
        attrSet _ = setAttributeKlass
        attrConstruct = undefined
        attrClear _ = clearAttributeKlass

    attribute_klass :: AttrLabelProxy "klass"
    attribute_klass = AttrLabelProxy

    #endif

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

    @
    'Data.GI.Base.Attributes.get' attribute #startIndex
    @
    -}
    getAttributeStartIndex :: MonadIO m => Attribute -> m Word32
    getAttributeStartIndex s = liftIO $ withManagedPtr s $ \ptr -> do
        val <- peek (ptr `plusPtr` 8) :: IO Word32
        return val

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

    @
    'Data.GI.Base.Attributes.set' attribute [ #startIndex 'Data.GI.Base.Attributes.:=' value ]
    @
    -}
    setAttributeStartIndex :: MonadIO m => Attribute -> Word32 -> m ()
    setAttributeStartIndex s val = liftIO $ withManagedPtr s $ \ptr -> do
        poke (ptr `plusPtr` 8) (val :: Word32)

    #if ENABLE_OVERLOADING
    data AttributeStartIndexFieldInfo
    instance AttrInfo AttributeStartIndexFieldInfo where
        type AttrAllowedOps AttributeStartIndexFieldInfo = '[ 'AttrSet, 'AttrGet]
        type AttrSetTypeConstraint AttributeStartIndexFieldInfo = (~) Word32
        type AttrBaseTypeConstraint AttributeStartIndexFieldInfo = (~) Attribute
        type AttrGetType AttributeStartIndexFieldInfo = Word32
        type AttrLabel AttributeStartIndexFieldInfo = "start_index"
        type AttrOrigin AttributeStartIndexFieldInfo = Attribute
        attrGet _ = getAttributeStartIndex
        attrSet _ = setAttributeStartIndex
        attrConstruct = undefined
        attrClear _ = undefined

    attribute_startIndex :: AttrLabelProxy "startIndex"
    attribute_startIndex = AttrLabelProxy

    #endif

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

    @
    'Data.GI.Base.Attributes.get' attribute #endIndex
    @
    -}
    getAttributeEndIndex :: MonadIO m => Attribute -> m Word32
    getAttributeEndIndex s = liftIO $ withManagedPtr s $ \ptr -> do
        val <- peek (ptr `plusPtr` 12) :: IO Word32
        return val

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

    @
    'Data.GI.Base.Attributes.set' attribute [ #endIndex 'Data.GI.Base.Attributes.:=' value ]
    @
    -}
    setAttributeEndIndex :: MonadIO m => Attribute -> Word32 -> m ()
    setAttributeEndIndex s val = liftIO $ withManagedPtr s $ \ptr -> do
        poke (ptr `plusPtr` 12) (val :: Word32)

    #if ENABLE_OVERLOADING
    data AttributeEndIndexFieldInfo
    instance AttrInfo AttributeEndIndexFieldInfo where
        type AttrAllowedOps AttributeEndIndexFieldInfo = '[ 'AttrSet, 'AttrGet]
        type AttrSetTypeConstraint AttributeEndIndexFieldInfo = (~) Word32
        type AttrBaseTypeConstraint AttributeEndIndexFieldInfo = (~) Attribute
        type AttrGetType AttributeEndIndexFieldInfo = Word32
        type AttrLabel AttributeEndIndexFieldInfo = "end_index"
        type AttrOrigin AttributeEndIndexFieldInfo = Attribute
        attrGet _ = getAttributeEndIndex
        attrSet _ = setAttributeEndIndex
        attrConstruct = undefined
        attrClear _ = undefined

    attribute_endIndex :: AttrLabelProxy "endIndex"
    attribute_endIndex = AttrLabelProxy

    #endif

    #if ENABLE_OVERLOADING
    instance O.HasAttributeList Attribute
    type instance O.AttributeList Attribute = AttributeAttributeList
    type AttributeAttributeList = ('[ '("klass", AttributeKlassFieldInfo), '("startIndex", AttributeStartIndexFieldInfo), '("endIndex", AttributeEndIndexFieldInfo)] :: [(Symbol, *)])
    #endif

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

    foreign import ccall "pango_attribute_destroy" pango_attribute_destroy ::
        Ptr Attribute ->                        -- attr : TInterface (Name {namespace = "Pango", name = "Attribute"})
        IO ()

    {- |
    Destroy a 'GI.Pango.Structs.Attribute.Attribute' and free all associated memory.
    -}
    attributeDestroy ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Attribute
        {- ^ /@attr@/: a 'GI.Pango.Structs.Attribute.Attribute'. -}
        -> m ()
    attributeDestroy attr = liftIO $ do
        attr' <- unsafeManagedPtrGetPtr attr
        pango_attribute_destroy attr'
        touchManagedPtr attr
        return ()

    #if ENABLE_OVERLOADING
    data AttributeDestroyMethodInfo
    instance (signature ~ (m ()), MonadIO m) => O.MethodInfo AttributeDestroyMethodInfo Attribute signature where
        overloadedMethod _ = attributeDestroy

    #endif

    -- method Attribute::equal
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "attr1", argType = TInterface (Name {namespace = "Pango", name = "Attribute"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #PangoAttribute", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "attr2", argType = TInterface (Name {namespace = "Pango", name = "Attribute"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "another #PangoAttribute", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Just (TBasicType TBoolean)
    -- throws : False
    -- Skip return : False

    foreign import ccall "pango_attribute_equal" pango_attribute_equal ::
        Ptr Attribute ->                        -- attr1 : TInterface (Name {namespace = "Pango", name = "Attribute"})
        Ptr Attribute ->                        -- attr2 : TInterface (Name {namespace = "Pango", name = "Attribute"})
        IO CInt

    {- |
    Compare two attributes for equality. This compares only the
    actual value of the two attributes and not the ranges that the
    attributes apply to.
    -}
    attributeEqual ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Attribute
        {- ^ /@attr1@/: a 'GI.Pango.Structs.Attribute.Attribute' -}
        -> Attribute
        {- ^ /@attr2@/: another 'GI.Pango.Structs.Attribute.Attribute' -}
        -> m Bool
        {- ^ __Returns:__ 'True' if the two attributes have the same value. -}
    attributeEqual attr1 attr2 = liftIO $ do
        attr1' <- unsafeManagedPtrGetPtr attr1
        attr2' <- unsafeManagedPtrGetPtr attr2
        result <- pango_attribute_equal attr1' attr2'
        let result' = (/= 0) result
        touchManagedPtr attr1
        touchManagedPtr attr2
        return result'

    #if ENABLE_OVERLOADING
    data AttributeEqualMethodInfo
    instance (signature ~ (Attribute -> m Bool), MonadIO m) => O.MethodInfo AttributeEqualMethodInfo Attribute signature where
        overloadedMethod _ = attributeEqual

    #endif

    -- method Attribute::init
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "attr", argType = TInterface (Name {namespace = "Pango", name = "Attribute"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #PangoAttribute", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "klass", argType = TInterface (Name {namespace = "Pango", name = "AttrClass"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #PangoAttrClass", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Nothing
    -- throws : False
    -- Skip return : False

    foreign import ccall "pango_attribute_init" pango_attribute_init ::
        Ptr Attribute ->                        -- attr : TInterface (Name {namespace = "Pango", name = "Attribute"})
        Ptr Pango.AttrClass.AttrClass ->        -- klass : TInterface (Name {namespace = "Pango", name = "AttrClass"})
        IO ()

    {- |
    Initializes /@attr@/\'s klass to /@klass@/,
    it\'s start_index to 'GI.Pango.Constants.ATTR_INDEX_FROM_TEXT_BEGINNING'
    and end_index to @/PANGO_ATTR_INDEX_TO_TEXT_END/@
    such that the attribute applies
    to the entire text by default.

    /Since: 1.20/
    -}
    attributeInit ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Attribute
        {- ^ /@attr@/: a 'GI.Pango.Structs.Attribute.Attribute' -}
        -> Pango.AttrClass.AttrClass
        {- ^ /@klass@/: a 'GI.Pango.Structs.AttrClass.AttrClass' -}
        -> m ()
    attributeInit attr klass = liftIO $ do
        attr' <- unsafeManagedPtrGetPtr attr
        klass' <- unsafeManagedPtrGetPtr klass
        pango_attribute_init attr' klass'
        touchManagedPtr attr
        touchManagedPtr klass
        return ()

    #if ENABLE_OVERLOADING
    data AttributeInitMethodInfo
    instance (signature ~ (Pango.AttrClass.AttrClass -> m ()), MonadIO m) => O.MethodInfo AttributeInitMethodInfo Attribute signature where
        overloadedMethod _ = attributeInit

    #endif

    #if ENABLE_OVERLOADING
    type family ResolveAttributeMethod (t :: Symbol) (o :: *) :: * where
        ResolveAttributeMethod "destroy" o = AttributeDestroyMethodInfo
        ResolveAttributeMethod "equal" o = AttributeEqualMethodInfo
        ResolveAttributeMethod "init" o = AttributeInitMethodInfo
        ResolveAttributeMethod l o = O.MethodResolutionFailed l o

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

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