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

Represents the line of a diff.
-}

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

module GI.Ggit.Structs.DiffLine
    (

-- * Exported types
    DiffLine(..)                            ,
    noDiffLine                              ,


 -- * Methods
-- ** getContent #method:getContent#

#if ENABLE_OVERLOADING
    DiffLineGetContentMethodInfo            ,
#endif
    diffLineGetContent                      ,


-- ** getContentOffset #method:getContentOffset#

#if ENABLE_OVERLOADING
    DiffLineGetContentOffsetMethodInfo      ,
#endif
    diffLineGetContentOffset                ,


-- ** getNewLineno #method:getNewLineno#

#if ENABLE_OVERLOADING
    DiffLineGetNewLinenoMethodInfo          ,
#endif
    diffLineGetNewLineno                    ,


-- ** getOldLineno #method:getOldLineno#

#if ENABLE_OVERLOADING
    DiffLineGetOldLinenoMethodInfo          ,
#endif
    diffLineGetOldLineno                    ,


-- ** getOrigin #method:getOrigin#

#if ENABLE_OVERLOADING
    DiffLineGetOriginMethodInfo             ,
#endif
    diffLineGetOrigin                       ,


-- ** getText #method:getText#

#if ENABLE_OVERLOADING
    DiffLineGetTextMethodInfo               ,
#endif
    diffLineGetText                         ,


-- ** ref #method:ref#

#if ENABLE_OVERLOADING
    DiffLineRefMethodInfo                   ,
#endif
    diffLineRef                             ,


-- ** unref #method:unref#

#if ENABLE_OVERLOADING
    DiffLineUnrefMethodInfo                 ,
#endif
    diffLineUnref                           ,




    ) 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

import {-# SOURCE #-} qualified GI.Ggit.Enums as Ggit.Enums

-- | Memory-managed wrapper type.
newtype DiffLine = DiffLine (ManagedPtr DiffLine)
foreign import ccall "ggit_diff_line_get_type" c_ggit_diff_line_get_type ::
    IO GType

instance BoxedObject DiffLine where
    boxedType _ = c_ggit_diff_line_get_type

-- | A convenience alias for `Nothing` :: `Maybe` `DiffLine`.
noDiffLine :: Maybe DiffLine
noDiffLine = Nothing


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

-- method DiffLine::get_content
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "line", argType = TInterface (Name {namespace = "Ggit", name = "DiffLine"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitDiffLine.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "length", argType = TBasicType TUInt64, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of returned bytes.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : [Arg {argCName = "length", argType = TBasicType TUInt64, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of returned bytes.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- returnType : Just (TCArray False (-1) 1 (TBasicType TUInt8))
-- throws : False
-- Skip return : False

foreign import ccall "ggit_diff_line_get_content" ggit_diff_line_get_content ::
    Ptr DiffLine ->                         -- line : TInterface (Name {namespace = "Ggit", name = "DiffLine"})
    Ptr Word64 ->                           -- length : TBasicType TUInt64
    IO (Ptr Word8)

{- |
Gets the content in bytes.
-}
diffLineGetContent ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    DiffLine
    {- ^ /@line@/: a 'GI.Ggit.Structs.DiffLine.DiffLine'. -}
    -> m ByteString
    {- ^ __Returns:__ the content in bytes. -}
diffLineGetContent line = liftIO $ do
    line' <- unsafeManagedPtrGetPtr line
    length_ <- allocMem :: IO (Ptr Word64)
    result <- ggit_diff_line_get_content line' length_
    length_' <- peek length_
    checkUnexpectedReturnNULL "diffLineGetContent" result
    result' <- (unpackByteStringWithLength length_') result
    touchManagedPtr line
    freeMem length_
    return result'

#if ENABLE_OVERLOADING
data DiffLineGetContentMethodInfo
instance (signature ~ (m ByteString), MonadIO m) => O.MethodInfo DiffLineGetContentMethodInfo DiffLine signature where
    overloadedMethod _ = diffLineGetContent

#endif

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

foreign import ccall "ggit_diff_line_get_content_offset" ggit_diff_line_get_content_offset ::
    Ptr DiffLine ->                         -- line : TInterface (Name {namespace = "Ggit", name = "DiffLine"})
    IO Int64

{- |
Gets the content offset.
-}
diffLineGetContentOffset ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    DiffLine
    {- ^ /@line@/: a 'GI.Ggit.Structs.DiffLine.DiffLine'. -}
    -> m Int64
    {- ^ __Returns:__ the content offset. -}
diffLineGetContentOffset line = liftIO $ do
    line' <- unsafeManagedPtrGetPtr line
    result <- ggit_diff_line_get_content_offset line'
    touchManagedPtr line
    return result

#if ENABLE_OVERLOADING
data DiffLineGetContentOffsetMethodInfo
instance (signature ~ (m Int64), MonadIO m) => O.MethodInfo DiffLineGetContentOffsetMethodInfo DiffLine signature where
    overloadedMethod _ = diffLineGetContentOffset

#endif

-- method DiffLine::get_new_lineno
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "line", argType = TInterface (Name {namespace = "Ggit", name = "DiffLine"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitDiffLine.", 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_diff_line_get_new_lineno" ggit_diff_line_get_new_lineno ::
    Ptr DiffLine ->                         -- line : TInterface (Name {namespace = "Ggit", name = "DiffLine"})
    IO Int32

{- |
Gets the Line number in new file or -1 for deleted line.
-}
diffLineGetNewLineno ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    DiffLine
    {- ^ /@line@/: a 'GI.Ggit.Structs.DiffLine.DiffLine'. -}
    -> m Int32
    {- ^ __Returns:__ the line\'s old number of lines. -}
diffLineGetNewLineno line = liftIO $ do
    line' <- unsafeManagedPtrGetPtr line
    result <- ggit_diff_line_get_new_lineno line'
    touchManagedPtr line
    return result

#if ENABLE_OVERLOADING
data DiffLineGetNewLinenoMethodInfo
instance (signature ~ (m Int32), MonadIO m) => O.MethodInfo DiffLineGetNewLinenoMethodInfo DiffLine signature where
    overloadedMethod _ = diffLineGetNewLineno

#endif

-- method DiffLine::get_old_lineno
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "line", argType = TInterface (Name {namespace = "Ggit", name = "DiffLine"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitDiffLine.", 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_diff_line_get_old_lineno" ggit_diff_line_get_old_lineno ::
    Ptr DiffLine ->                         -- line : TInterface (Name {namespace = "Ggit", name = "DiffLine"})
    IO Int32

{- |
Gets the line number in old file or -1 for added line.
-}
diffLineGetOldLineno ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    DiffLine
    {- ^ /@line@/: a 'GI.Ggit.Structs.DiffLine.DiffLine'. -}
    -> m Int32
    {- ^ __Returns:__ the line\'s old line number. -}
diffLineGetOldLineno line = liftIO $ do
    line' <- unsafeManagedPtrGetPtr line
    result <- ggit_diff_line_get_old_lineno line'
    touchManagedPtr line
    return result

#if ENABLE_OVERLOADING
data DiffLineGetOldLinenoMethodInfo
instance (signature ~ (m Int32), MonadIO m) => O.MethodInfo DiffLineGetOldLinenoMethodInfo DiffLine signature where
    overloadedMethod _ = diffLineGetOldLineno

#endif

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

foreign import ccall "ggit_diff_line_get_origin" ggit_diff_line_get_origin ::
    Ptr DiffLine ->                         -- line : TInterface (Name {namespace = "Ggit", name = "DiffLine"})
    IO CUInt

{- |
Gets the 'GI.Ggit.Enums.DiffLineType' value.
-}
diffLineGetOrigin ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    DiffLine
    {- ^ /@line@/: a 'GI.Ggit.Structs.DiffLine.DiffLine'. -}
    -> m Ggit.Enums.DiffLineType
    {- ^ __Returns:__ the 'GI.Ggit.Enums.DiffLineType' value. -}
diffLineGetOrigin line = liftIO $ do
    line' <- unsafeManagedPtrGetPtr line
    result <- ggit_diff_line_get_origin line'
    let result' = (toEnum . fromIntegral) result
    touchManagedPtr line
    return result'

#if ENABLE_OVERLOADING
data DiffLineGetOriginMethodInfo
instance (signature ~ (m Ggit.Enums.DiffLineType), MonadIO m) => O.MethodInfo DiffLineGetOriginMethodInfo DiffLine signature where
    overloadedMethod _ = diffLineGetOrigin

#endif

-- method DiffLine::get_text
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "line", argType = TInterface (Name {namespace = "Ggit", name = "DiffLine"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitDiffLine.", 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_diff_line_get_text" ggit_diff_line_get_text ::
    Ptr DiffLine ->                         -- line : TInterface (Name {namespace = "Ggit", name = "DiffLine"})
    IO CString

{- |
Get the content of the diff line as UTF-8 encoded text.
-}
diffLineGetText ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    DiffLine
    {- ^ /@line@/: a 'GI.Ggit.Structs.DiffLine.DiffLine'. -}
    -> m (Maybe T.Text)
    {- ^ __Returns:__ the content in utf-8 encoding or 'Nothing'. -}
diffLineGetText line = liftIO $ do
    line' <- unsafeManagedPtrGetPtr line
    result <- ggit_diff_line_get_text line'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToText result'
        return result''
    touchManagedPtr line
    return maybeResult

#if ENABLE_OVERLOADING
data DiffLineGetTextMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m) => O.MethodInfo DiffLineGetTextMethodInfo DiffLine signature where
    overloadedMethod _ = diffLineGetText

#endif

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

foreign import ccall "ggit_diff_line_ref" ggit_diff_line_ref ::
    Ptr DiffLine ->                         -- line : TInterface (Name {namespace = "Ggit", name = "DiffLine"})
    IO (Ptr DiffLine)

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

#if ENABLE_OVERLOADING
data DiffLineRefMethodInfo
instance (signature ~ (m (Maybe DiffLine)), MonadIO m) => O.MethodInfo DiffLineRefMethodInfo DiffLine signature where
    overloadedMethod _ = diffLineRef

#endif

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

foreign import ccall "ggit_diff_line_unref" ggit_diff_line_unref ::
    Ptr DiffLine ->                         -- line : TInterface (Name {namespace = "Ggit", name = "DiffLine"})
    IO ()

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

#if ENABLE_OVERLOADING
data DiffLineUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo DiffLineUnrefMethodInfo DiffLine signature where
    overloadedMethod _ = diffLineUnref

#endif

#if ENABLE_OVERLOADING
type family ResolveDiffLineMethod (t :: Symbol) (o :: *) :: * where
    ResolveDiffLineMethod "ref" o = DiffLineRefMethodInfo
    ResolveDiffLineMethod "unref" o = DiffLineUnrefMethodInfo
    ResolveDiffLineMethod "getContent" o = DiffLineGetContentMethodInfo
    ResolveDiffLineMethod "getContentOffset" o = DiffLineGetContentOffsetMethodInfo
    ResolveDiffLineMethod "getNewLineno" o = DiffLineGetNewLinenoMethodInfo
    ResolveDiffLineMethod "getOldLineno" o = DiffLineGetOldLinenoMethodInfo
    ResolveDiffLineMethod "getOrigin" o = DiffLineGetOriginMethodInfo
    ResolveDiffLineMethod "getText" o = DiffLineGetTextMethodInfo
    ResolveDiffLineMethod l o = O.MethodResolutionFailed l o

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