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

Reprensents a git reference specification.
-}

module GI.Ggit.Structs.RefSpec
    ( 

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


 -- * Methods
-- ** getDestination #method:getDestination#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    RefSpecGetDestinationMethodInfo         ,
#endif
    refSpecGetDestination                   ,


-- ** getSource #method:getSource#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    RefSpecGetSourceMethodInfo              ,
#endif
    refSpecGetSource                        ,


-- ** isForced #method:isForced#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    RefSpecIsForcedMethodInfo               ,
#endif
    refSpecIsForced                         ,


-- ** ref #method:ref#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    RefSpecRefMethodInfo                    ,
#endif
    refSpecRef                              ,


-- ** unref #method:unref#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    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.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


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

noRefSpec :: Maybe RefSpec
noRefSpec = Nothing


#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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 T.Text
    {- ^ __Returns:__ the refspec\'s destination. -}
refSpecGetDestination refspec = liftIO $ do
    refspec' <- unsafeManagedPtrGetPtr refspec
    result <- ggit_ref_spec_get_destination refspec'
    checkUnexpectedReturnNULL "refSpecGetDestination" result
    result' <- cstringToText result
    touchManagedPtr refspec
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data RefSpecGetDestinationMethodInfo
instance (signature ~ (m 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 T.Text
    {- ^ __Returns:__ the refspec\'s source. -}
refSpecGetSource refspec = liftIO $ do
    refspec' <- unsafeManagedPtrGetPtr refspec
    result <- ggit_ref_spec_get_source refspec'
    checkUnexpectedReturnNULL "refSpecGetSource" result
    result' <- cstringToText result
    touchManagedPtr refspec
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data RefSpecGetSourceMethodInfo
instance (signature ~ (m 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 defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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 RefSpec
    {- ^ __Returns:__ a 'GI.Ggit.Structs.RefSpec.RefSpec'. -}
refSpecRef refspec = liftIO $ do
    refspec' <- unsafeManagedPtrGetPtr refspec
    result <- ggit_ref_spec_ref refspec'
    checkUnexpectedReturnNULL "refSpecRef" result
    result' <- (wrapBoxed RefSpec) result
    touchManagedPtr refspec
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data RefSpecRefMethodInfo
instance (signature ~ (m 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 defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data RefSpecUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo RefSpecUnrefMethodInfo RefSpec signature where
    overloadedMethod _ = refSpecUnref

#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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) => O.IsLabelProxy t (RefSpec -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

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

#endif