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

Reprensents a git reference specification.
-}

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

module GI.Ggit.Structs.RefSpec
    (

-- * Exported types
    RefSpec(..)                             ,
    noRefSpec                               ,


 -- * Methods
-- ** getDestination #method:getDestination#

#if ENABLE_OVERLOADING
    RefSpecGetDestinationMethodInfo         ,
#endif
    refSpecGetDestination                   ,


-- ** getSource #method:getSource#

#if ENABLE_OVERLOADING
    RefSpecGetSourceMethodInfo              ,
#endif
    refSpecGetSource                        ,


-- ** isForced #method:isForced#

#if ENABLE_OVERLOADING
    RefSpecIsForcedMethodInfo               ,
#endif
    refSpecIsForced                         ,


-- ** ref #method:ref#

#if ENABLE_OVERLOADING
    RefSpecRefMethodInfo                    ,
#endif
    refSpecRef                              ,


-- ** unref #method:unref#

#if ENABLE_OVERLOADING
    RefSpecUnrefMethodInfo                  ,
#endif
    refSpecUnref                            ,




    ) 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


-- | Memory-managed wrapper type.
newtype RefSpec = RefSpec (ManagedPtr RefSpec)
foreign import ccall "ggit_ref_spec_get_type" c_ggit_ref_spec_get_type ::
    IO GType

instance BoxedObject RefSpec where
    boxedType _ = c_ggit_ref_spec_get_type

-- | A convenience alias for `Nothing` :: `Maybe` `RefSpec`.
noRefSpec :: Maybe RefSpec
noRefSpec = Nothing


#if ENABLE_OVERLOADING
instance O.HasAttributeList RefSpec
type instance O.AttributeList RefSpec = RefSpecAttributeList
type RefSpecAttributeList = ('[ ] :: [(Symbol, *)])
#endif

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

foreign import ccall "ggit_ref_spec_get_destination" ggit_ref_spec_get_destination ::
    Ptr RefSpec ->                          -- refspec : TInterface (Name {namespace = "Ggit", name = "RefSpec"})
    IO CString

{- |
Gets the /@refspec@/\'s destination.
-}
refSpecGetDestination ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    RefSpec
    {- ^ /@refspec@/: a 'GI.Ggit.Structs.RefSpec.RefSpec'. -}
    -> m (Maybe T.Text)
    {- ^ __Returns:__ the refspec\'s destination or 'Nothing'. -}
refSpecGetDestination refspec = liftIO $ do
    refspec' <- unsafeManagedPtrGetPtr refspec
    result <- ggit_ref_spec_get_destination refspec'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToText result'
        return result''
    touchManagedPtr refspec
    return maybeResult

#if ENABLE_OVERLOADING
data RefSpecGetDestinationMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m) => O.MethodInfo RefSpecGetDestinationMethodInfo RefSpec signature where
    overloadedMethod _ = refSpecGetDestination

#endif

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

foreign import ccall "ggit_ref_spec_get_source" ggit_ref_spec_get_source ::
    Ptr RefSpec ->                          -- refspec : TInterface (Name {namespace = "Ggit", name = "RefSpec"})
    IO CString

{- |
Gets the /@refspec@/\'s source.
-}
refSpecGetSource ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    RefSpec
    {- ^ /@refspec@/: a 'GI.Ggit.Structs.RefSpec.RefSpec'. -}
    -> m (Maybe T.Text)
    {- ^ __Returns:__ the refspec\'s source or 'Nothing'. -}
refSpecGetSource refspec = liftIO $ do
    refspec' <- unsafeManagedPtrGetPtr refspec
    result <- ggit_ref_spec_get_source refspec'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToText result'
        return result''
    touchManagedPtr refspec
    return maybeResult

#if ENABLE_OVERLOADING
data RefSpecGetSourceMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m) => O.MethodInfo RefSpecGetSourceMethodInfo RefSpec signature where
    overloadedMethod _ = refSpecGetSource

#endif

-- method RefSpec::is_forced
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "refspec", argType = TInterface (Name {namespace = "Ggit", name = "RefSpec"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitRefSpec.", 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 "ggit_ref_spec_is_forced" ggit_ref_spec_is_forced ::
    Ptr RefSpec ->                          -- refspec : TInterface (Name {namespace = "Ggit", name = "RefSpec"})
    IO CInt

{- |
Whether updating is done forcefully.
-}
refSpecIsForced ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    RefSpec
    {- ^ /@refspec@/: a 'GI.Ggit.Structs.RefSpec.RefSpec'. -}
    -> m Bool
    {- ^ __Returns:__ if updating is done forcefully. -}
refSpecIsForced refspec = liftIO $ do
    refspec' <- unsafeManagedPtrGetPtr refspec
    result <- ggit_ref_spec_is_forced refspec'
    let result' = (/= 0) result
    touchManagedPtr refspec
    return result'

#if ENABLE_OVERLOADING
data RefSpecIsForcedMethodInfo
instance (signature ~ (m Bool), MonadIO m) => O.MethodInfo RefSpecIsForcedMethodInfo RefSpec signature where
    overloadedMethod _ = refSpecIsForced

#endif

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

foreign import ccall "ggit_ref_spec_ref" ggit_ref_spec_ref ::
    Ptr RefSpec ->                          -- refspec : TInterface (Name {namespace = "Ggit", name = "RefSpec"})
    IO (Ptr RefSpec)

{- |
Atomically increments the reference count of /@refspec@/ by one.
This function is MT-safe and may be called from any thread.
-}
refSpecRef ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    RefSpec
    {- ^ /@refspec@/: a 'GI.Ggit.Structs.RefSpec.RefSpec'. -}
    -> m (Maybe RefSpec)
    {- ^ __Returns:__ a 'GI.Ggit.Structs.RefSpec.RefSpec' or 'Nothing'. -}
refSpecRef refspec = liftIO $ do
    refspec' <- unsafeManagedPtrGetPtr refspec
    result <- ggit_ref_spec_ref refspec'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (newBoxed RefSpec) result'
        return result''
    touchManagedPtr refspec
    return maybeResult

#if ENABLE_OVERLOADING
data RefSpecRefMethodInfo
instance (signature ~ (m (Maybe RefSpec)), MonadIO m) => O.MethodInfo RefSpecRefMethodInfo RefSpec signature where
    overloadedMethod _ = refSpecRef

#endif

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

foreign import ccall "ggit_ref_spec_unref" ggit_ref_spec_unref ::
    Ptr RefSpec ->                          -- refspec : TInterface (Name {namespace = "Ggit", name = "RefSpec"})
    IO ()

{- |
Atomically decrements the reference count of /@refspec@/ by one.
If the reference count drops to 0, /@refspec@/ is freed.
-}
refSpecUnref ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    RefSpec
    {- ^ /@refspec@/: a 'GI.Ggit.Structs.RefSpec.RefSpec'. -}
    -> m ()
refSpecUnref refspec = liftIO $ do
    refspec' <- unsafeManagedPtrGetPtr refspec
    ggit_ref_spec_unref refspec'
    touchManagedPtr refspec
    return ()

#if ENABLE_OVERLOADING
data RefSpecUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo RefSpecUnrefMethodInfo RefSpec signature where
    overloadedMethod _ = refSpecUnref

#endif

#if ENABLE_OVERLOADING
type family ResolveRefSpecMethod (t :: Symbol) (o :: *) :: * where
    ResolveRefSpecMethod "isForced" o = RefSpecIsForcedMethodInfo
    ResolveRefSpecMethod "ref" o = RefSpecRefMethodInfo
    ResolveRefSpecMethod "unref" o = RefSpecUnrefMethodInfo
    ResolveRefSpecMethod "getDestination" o = RefSpecGetDestinationMethodInfo
    ResolveRefSpecMethod "getSource" o = RefSpecGetSourceMethodInfo
    ResolveRefSpecMethod l o = O.MethodResolutionFailed l o

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