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

Represents a unique ID of any object.
-}

module GI.Ggit.Structs.OId
    ( 

-- * Exported types
    OId(..)                                 ,
    noOId                                   ,


 -- * Methods
-- ** compare #method:compare#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    OIdCompareMethodInfo                    ,
#endif
    oIdCompare                              ,


-- ** copy #method:copy#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    OIdCopyMethodInfo                       ,
#endif
    oIdCopy                                 ,


-- ** equal #method:equal#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    OIdEqualMethodInfo                      ,
#endif
    oIdEqual                                ,


-- ** free #method:free#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    OIdFreeMethodInfo                       ,
#endif
    oIdFree                                 ,


-- ** hasPrefix #method:hasPrefix#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    OIdHasPrefixMethodInfo                  ,
#endif
    oIdHasPrefix                            ,


-- ** hash #method:hash#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    OIdHashMethodInfo                       ,
#endif
    oIdHash                                 ,


-- ** isZero #method:isZero#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    OIdIsZeroMethodInfo                     ,
#endif
    oIdIsZero                               ,


-- ** newFromRaw #method:newFromRaw#
    oIdNewFromRaw                           ,


-- ** newFromString #method:newFromString#
    oIdNewFromString                        ,


-- ** toString #method:toString#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    OIdToStringMethodInfo                   ,
#endif
    oIdToString                             ,




    ) 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 OId = OId (ManagedPtr OId)
foreign import ccall "ggit_oid_get_type" c_ggit_oid_get_type :: 
    IO GType

instance BoxedObject OId where
    boxedType _ = c_ggit_oid_get_type

noOId :: Maybe OId
noOId = Nothing


#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
instance O.HasAttributeList OId
type instance O.AttributeList OId = OIdAttributeList
type OIdAttributeList = ('[ ] :: [(Symbol, *)])
#endif

-- method OId::new_from_raw
-- method type : Constructor
-- Args : [Arg {argCName = "raw", argType = TBasicType TUInt8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the raw input bytes to be copied.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "OId"}))
-- throws : False
-- Skip return : False

foreign import ccall "ggit_oid_new_from_raw" ggit_oid_new_from_raw :: 
    Word8 ->                                -- raw : TBasicType TUInt8
    IO (Ptr OId)

{- |
Creates a new 'GI.Ggit.Structs.OId.OId' from a raw oid.
-}
oIdNewFromRaw ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Word8
    {- ^ /@raw@/: the raw input bytes to be copied. -}
    -> m OId
    {- ^ __Returns:__ a newly allocated 'GI.Ggit.Structs.OId.OId'. -}
oIdNewFromRaw raw = liftIO $ do
    result <- ggit_oid_new_from_raw raw
    checkUnexpectedReturnNULL "oIdNewFromRaw" result
    result' <- (wrapBoxed OId) result
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
#endif

-- method OId::new_from_string
-- method type : Constructor
-- Args : [Arg {argCName = "str", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "input hex string; must be pointing at the start of\n      the hex sequence and have at least the number of bytes\n      needed for an oid encoded in hex (40 bytes).", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "OId"}))
-- throws : False
-- Skip return : False

foreign import ccall "ggit_oid_new_from_string" ggit_oid_new_from_string :: 
    CString ->                              -- str : TBasicType TUTF8
    IO (Ptr OId)

{- |
Parses a hex formatted object id into a 'GI.Ggit.Structs.OId.OId'.
-}
oIdNewFromString ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@str@/: input hex string; must be pointing at the start of
      the hex sequence and have at least the number of bytes
      needed for an oid encoded in hex (40 bytes). -}
    -> m OId
    {- ^ __Returns:__ a newly allocated 'GI.Ggit.Structs.OId.OId' or 'Nothing' on error. -}
oIdNewFromString str = liftIO $ do
    str' <- textToCString str
    result <- ggit_oid_new_from_string str'
    checkUnexpectedReturnNULL "oIdNewFromString" result
    result' <- (wrapBoxed OId) result
    freeMem str'
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
#endif

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

foreign import ccall "ggit_oid_compare" ggit_oid_compare :: 
    Ptr OId ->                              -- a : TInterface (Name {namespace = "Ggit", name = "OId"})
    Ptr OId ->                              -- b : TInterface (Name {namespace = "Ggit", name = "OId"})
    IO Int32

{- |
Compare two 'GI.Ggit.Structs.OId.OId' structures.
-}
oIdCompare ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    OId
    {- ^ /@a@/: first 'GI.Ggit.Structs.OId.OId'. -}
    -> OId
    {- ^ /@b@/: second 'GI.Ggit.Structs.OId.OId'. -}
    -> m Int32
    {- ^ __Returns:__ \<0, 0, >0 if a \< b, a == b, a > b. -}
oIdCompare a b = liftIO $ do
    a' <- unsafeManagedPtrGetPtr a
    b' <- unsafeManagedPtrGetPtr b
    result <- ggit_oid_compare a' b'
    touchManagedPtr a
    touchManagedPtr b
    return result

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data OIdCompareMethodInfo
instance (signature ~ (OId -> m Int32), MonadIO m) => O.MethodInfo OIdCompareMethodInfo OId signature where
    overloadedMethod _ = oIdCompare

#endif

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

foreign import ccall "ggit_oid_copy" ggit_oid_copy :: 
    Ptr OId ->                              -- oid : TInterface (Name {namespace = "Ggit", name = "OId"})
    IO (Ptr OId)

{- |
Copies /@oid@/ into a newly allocated 'GI.Ggit.Structs.OId.OId'.
-}
oIdCopy ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    OId
    {- ^ /@oid@/: a 'GI.Ggit.Structs.OId.OId'. -}
    -> m OId
    {- ^ __Returns:__ a newly allocated 'GI.Ggit.Structs.OId.OId'. -}
oIdCopy oid = liftIO $ do
    oid' <- unsafeManagedPtrGetPtr oid
    result <- ggit_oid_copy oid'
    checkUnexpectedReturnNULL "oIdCopy" result
    result' <- (wrapBoxed OId) result
    touchManagedPtr oid
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data OIdCopyMethodInfo
instance (signature ~ (m OId), MonadIO m) => O.MethodInfo OIdCopyMethodInfo OId signature where
    overloadedMethod _ = oIdCopy

#endif

-- method OId::equal
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "a", argType = TInterface (Name {namespace = "Ggit", name = "OId"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitOId.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "b", argType = TInterface (Name {namespace = "Ggit", name = "OId"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitOId.", 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_oid_equal" ggit_oid_equal :: 
    Ptr OId ->                              -- a : TInterface (Name {namespace = "Ggit", name = "OId"})
    Ptr OId ->                              -- b : TInterface (Name {namespace = "Ggit", name = "OId"})
    IO CInt

{- |
Compares two 'GI.Ggit.Structs.OId.OId' for equality.
-}
oIdEqual ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    OId
    {- ^ /@a@/: a 'GI.Ggit.Structs.OId.OId'. -}
    -> OId
    {- ^ /@b@/: a 'GI.Ggit.Structs.OId.OId'. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if /@a@/ and /@b@/ are equal, 'False' otherwise -}
oIdEqual a b = liftIO $ do
    a' <- unsafeManagedPtrGetPtr a
    b' <- unsafeManagedPtrGetPtr b
    result <- ggit_oid_equal a' b'
    let result' = (/= 0) result
    touchManagedPtr a
    touchManagedPtr b
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data OIdEqualMethodInfo
instance (signature ~ (OId -> m Bool), MonadIO m) => O.MethodInfo OIdEqualMethodInfo OId signature where
    overloadedMethod _ = oIdEqual

#endif

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

foreign import ccall "ggit_oid_free" ggit_oid_free :: 
    Ptr OId ->                              -- oid : TInterface (Name {namespace = "Ggit", name = "OId"})
    IO ()

{- |
Frees /@oid@/.
-}
oIdFree ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    OId
    {- ^ /@oid@/: a 'GI.Ggit.Structs.OId.OId'. -}
    -> m ()
oIdFree oid = liftIO $ do
    oid' <- unsafeManagedPtrGetPtr oid
    ggit_oid_free oid'
    touchManagedPtr oid
    return ()

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data OIdFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo OIdFreeMethodInfo OId signature where
    overloadedMethod _ = oIdFree

#endif

-- method OId::has_prefix
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "oid", argType = TInterface (Name {namespace = "Ggit", name = "OId"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitOId.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "prefix", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a prefix.", 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_oid_has_prefix" ggit_oid_has_prefix :: 
    Ptr OId ->                              -- oid : TInterface (Name {namespace = "Ggit", name = "OId"})
    CString ->                              -- prefix : TBasicType TUTF8
    IO CInt

{- |
Check whether the object id has a given prefix. Note that the prefix is
specified in hexadecimal ASCII.
-}
oIdHasPrefix ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    OId
    {- ^ /@oid@/: a 'GI.Ggit.Structs.OId.OId'. -}
    -> T.Text
    {- ^ /@prefix@/: a prefix. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the id has the given prefix, 'False' otherwise. -}
oIdHasPrefix oid prefix = liftIO $ do
    oid' <- unsafeManagedPtrGetPtr oid
    prefix' <- textToCString prefix
    result <- ggit_oid_has_prefix oid' prefix'
    let result' = (/= 0) result
    touchManagedPtr oid
    freeMem prefix'
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data OIdHasPrefixMethodInfo
instance (signature ~ (T.Text -> m Bool), MonadIO m) => O.MethodInfo OIdHasPrefixMethodInfo OId signature where
    overloadedMethod _ = oIdHasPrefix

#endif

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

foreign import ccall "ggit_oid_hash" ggit_oid_hash :: 
    Ptr OId ->                              -- oid : TInterface (Name {namespace = "Ggit", name = "OId"})
    IO Word32

{- |
Computes a hash value for a git object identifier.
-}
oIdHash ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    OId
    {- ^ /@oid@/: a 'GI.Ggit.Structs.OId.OId'. -}
    -> m Word32
    {- ^ __Returns:__ the hash value -}
oIdHash oid = liftIO $ do
    oid' <- unsafeManagedPtrGetPtr oid
    result <- ggit_oid_hash oid'
    touchManagedPtr oid
    return result

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data OIdHashMethodInfo
instance (signature ~ (m Word32), MonadIO m) => O.MethodInfo OIdHashMethodInfo OId signature where
    overloadedMethod _ = oIdHash

#endif

-- method OId::is_zero
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "oid", argType = TInterface (Name {namespace = "Ggit", name = "OId"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitOId.", 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_oid_is_zero" ggit_oid_is_zero :: 
    Ptr OId ->                              -- oid : TInterface (Name {namespace = "Ggit", name = "OId"})
    IO CInt

{- |
Get whether the oid contains only zeros.
-}
oIdIsZero ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    OId
    {- ^ /@oid@/: a 'GI.Ggit.Structs.OId.OId'. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the oid contains only zeros, 'False' otherwise. -}
oIdIsZero oid = liftIO $ do
    oid' <- unsafeManagedPtrGetPtr oid
    result <- ggit_oid_is_zero oid'
    let result' = (/= 0) result
    touchManagedPtr oid
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data OIdIsZeroMethodInfo
instance (signature ~ (m Bool), MonadIO m) => O.MethodInfo OIdIsZeroMethodInfo OId signature where
    overloadedMethod _ = oIdIsZero

#endif

-- method OId::to_string
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "oid", argType = TInterface (Name {namespace = "Ggit", name = "OId"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitOId.", 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_oid_to_string" ggit_oid_to_string :: 
    Ptr OId ->                              -- oid : TInterface (Name {namespace = "Ggit", name = "OId"})
    IO CString

{- |
Converts /@oid@/ into a readable string.
-}
oIdToString ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    OId
    {- ^ /@oid@/: a 'GI.Ggit.Structs.OId.OId'. -}
    -> m T.Text
    {- ^ __Returns:__ a newly allocated string representing /@oid@/. -}
oIdToString oid = liftIO $ do
    oid' <- unsafeManagedPtrGetPtr oid
    result <- ggit_oid_to_string oid'
    checkUnexpectedReturnNULL "oIdToString" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr oid
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data OIdToStringMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.MethodInfo OIdToStringMethodInfo OId signature where
    overloadedMethod _ = oIdToString

#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type family ResolveOIdMethod (t :: Symbol) (o :: *) :: * where
    ResolveOIdMethod "compare" o = OIdCompareMethodInfo
    ResolveOIdMethod "copy" o = OIdCopyMethodInfo
    ResolveOIdMethod "equal" o = OIdEqualMethodInfo
    ResolveOIdMethod "free" o = OIdFreeMethodInfo
    ResolveOIdMethod "hasPrefix" o = OIdHasPrefixMethodInfo
    ResolveOIdMethod "hash" o = OIdHashMethodInfo
    ResolveOIdMethod "isZero" o = OIdIsZeroMethodInfo
    ResolveOIdMethod "toString" o = OIdToStringMethodInfo
    ResolveOIdMethod l o = O.MethodResolutionFailed l o

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

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