    {- |
    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.AttrLanguage.AttrLanguage' structure is used to represent attributes that
    are languages.
    -}

    #define ENABLE_OVERLOADING \
           (!defined(__HADDOCK_VERSION__))

    module GI.Pango.Structs.AttrLanguage
        (

    -- * Exported types
        AttrLanguage(..)                        ,
        newZeroAttrLanguage                     ,
        noAttrLanguage                          ,

     -- * Methods
    -- ** new #method:new#

        attrLanguageNew                         ,

     -- * Properties
    -- ** attr #attr:attr#
    {- | the common portion of the attribute
    -}
    #if ENABLE_OVERLOADING
        attrLanguage_attr                       ,
    #endif
        getAttrLanguageAttr                     ,

    -- ** value #attr:value#
    {- | the 'GI.Pango.Structs.Language.Language' which is the value of the attribute
    -}
    #if ENABLE_OVERLOADING
        attrLanguage_value                      ,
    #endif
        clearAttrLanguageValue                  ,
        getAttrLanguageValue                    ,
        setAttrLanguageValue                    ,

        ) 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.Attribute as Pango.Attribute
    import {-# SOURCE #-} qualified GI.Pango.Structs.Language as Pango.Language

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

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

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

    -- | A convenience alias for `Nothing` :: `Maybe` `AttrLanguage`.
    noAttrLanguage :: Maybe AttrLanguage
    noAttrLanguage = Nothing

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

    @
    'Data.GI.Base.Attributes.get' attrLanguage #attr
    @
    -}
    getAttrLanguageAttr :: MonadIO m => AttrLanguage -> m Pango.Attribute.Attribute
    getAttrLanguageAttr s = liftIO $ withManagedPtr s $ \ptr -> do
        let val = ptr `plusPtr` 0 :: (Ptr Pango.Attribute.Attribute)
        val' <- (newPtr Pango.Attribute.Attribute) val
        return val'

    #if ENABLE_OVERLOADING
    data AttrLanguageAttrFieldInfo
    instance AttrInfo AttrLanguageAttrFieldInfo where
        type AttrAllowedOps AttrLanguageAttrFieldInfo = '[ 'AttrGet]
        type AttrSetTypeConstraint AttrLanguageAttrFieldInfo = (~) (Ptr Pango.Attribute.Attribute)
        type AttrBaseTypeConstraint AttrLanguageAttrFieldInfo = (~) AttrLanguage
        type AttrGetType AttrLanguageAttrFieldInfo = Pango.Attribute.Attribute
        type AttrLabel AttrLanguageAttrFieldInfo = "attr"
        type AttrOrigin AttrLanguageAttrFieldInfo = AttrLanguage
        attrGet _ = getAttrLanguageAttr
        attrSet _ = undefined
        attrConstruct = undefined
        attrClear _ = undefined

    attrLanguage_attr :: AttrLabelProxy "attr"
    attrLanguage_attr = AttrLabelProxy

    #endif

    {- |
    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' attrLanguage #value
    @
    -}
    getAttrLanguageValue :: MonadIO m => AttrLanguage -> m (Maybe Pango.Language.Language)
    getAttrLanguageValue s = liftIO $ withManagedPtr s $ \ptr -> do
        val <- peek (ptr `plusPtr` 16) :: IO (Ptr Pango.Language.Language)
        result <- SP.convertIfNonNull val $ \val' -> do
            val'' <- (newBoxed Pango.Language.Language) val'
            return val''
        return result

    {- |
    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' attrLanguage [ #value 'Data.GI.Base.Attributes.:=' value ]
    @
    -}
    setAttrLanguageValue :: MonadIO m => AttrLanguage -> Ptr Pango.Language.Language -> m ()
    setAttrLanguageValue s val = liftIO $ withManagedPtr s $ \ptr -> do
        poke (ptr `plusPtr` 16) (val :: Ptr Pango.Language.Language)

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

    #if ENABLE_OVERLOADING
    data AttrLanguageValueFieldInfo
    instance AttrInfo AttrLanguageValueFieldInfo where
        type AttrAllowedOps AttrLanguageValueFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
        type AttrSetTypeConstraint AttrLanguageValueFieldInfo = (~) (Ptr Pango.Language.Language)
        type AttrBaseTypeConstraint AttrLanguageValueFieldInfo = (~) AttrLanguage
        type AttrGetType AttrLanguageValueFieldInfo = Maybe Pango.Language.Language
        type AttrLabel AttrLanguageValueFieldInfo = "value"
        type AttrOrigin AttrLanguageValueFieldInfo = AttrLanguage
        attrGet _ = getAttrLanguageValue
        attrSet _ = setAttrLanguageValue
        attrConstruct = undefined
        attrClear _ = clearAttrLanguageValue

    attrLanguage_value :: AttrLabelProxy "value"
    attrLanguage_value = AttrLabelProxy

    #endif

    #if ENABLE_OVERLOADING
    instance O.HasAttributeList AttrLanguage
    type instance O.AttributeList AttrLanguage = AttrLanguageAttributeList
    type AttrLanguageAttributeList = ('[ '("attr", AttrLanguageAttrFieldInfo), '("value", AttrLanguageValueFieldInfo)] :: [(Symbol, *)])
    #endif

    -- method AttrLanguage::new
    -- method type : MemberFunction
    -- Args : [Arg {argCName = "language", argType = TInterface (Name {namespace = "Pango", name = "Language"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "language tag", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Just (TInterface (Name {namespace = "Pango", name = "Attribute"}))
    -- throws : False
    -- Skip return : False

    foreign import ccall "pango_attr_language_new" pango_attr_language_new ::
        Ptr Pango.Language.Language ->          -- language : TInterface (Name {namespace = "Pango", name = "Language"})
        IO (Ptr Pango.Attribute.Attribute)

    {- |
    Create a new language tag attribute.
    -}
    attrLanguageNew ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Pango.Language.Language
        {- ^ /@language@/: language tag -}
        -> m Pango.Attribute.Attribute
        {- ^ __Returns:__ the newly allocated 'GI.Pango.Structs.Attribute.Attribute',
                  which should be freed with 'GI.Pango.Structs.Attribute.attributeDestroy'. -}
    attrLanguageNew language = liftIO $ do
        language' <- unsafeManagedPtrGetPtr language
        result <- pango_attr_language_new language'
        checkUnexpectedReturnNULL "attrLanguageNew" result
        result' <- (wrapPtr Pango.Attribute.Attribute) result
        touchManagedPtr language
        return result'

    #if ENABLE_OVERLOADING
    #endif

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

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

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