-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria

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

module GI.Ggit.Functions
    ( 

 -- * Methods


-- ** getFeatures #method:getFeatures#

    getFeatures                             ,


-- ** init #method:init#

    init                                    ,


-- ** messagePrettify #method:messagePrettify#

    messagePrettify                         ,




    ) 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.BasicTypes as B.Types
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GArray as B.GArray
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GHashTable as B.GHT
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.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
import qualified Data.Coerce as Coerce
import qualified Data.Text as T
import qualified Data.Kind as DK
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 qualified GHC.Records as R

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

-- function message_prettify
-- Args: [ Arg
--           { argCName = "message"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the message." , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "strip_comments"
--           , argType = TBasicType TBoolean
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "whether to strip comments."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "comment_char"
--           , argType = TBasicType TInt8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "comment character." , 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_message_prettify" ggit_message_prettify :: 
    CString ->                              -- message : TBasicType TUTF8
    CInt ->                                 -- strip_comments : TBasicType TBoolean
    Int8 ->                                 -- comment_char : TBasicType TInt8
    IO CString

-- | Prettify a commit message by removing excess whitespace and making sure the
-- last line ends with a newline. If /@stripComments@/ is 'P.True', then lines
-- starting with a /@commentChar@/ will be removed.
messagePrettify ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    -- ^ /@message@/: the message.
    -> Bool
    -- ^ /@stripComments@/: whether to strip comments.
    -> Int8
    -- ^ /@commentChar@/: comment character.
    -> m T.Text
    -- ^ __Returns:__ the prettified message.
messagePrettify :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> Bool -> Int8 -> m Text
messagePrettify Text
message Bool
stripComments Int8
commentChar = IO Text -> m Text
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Text -> m Text) -> IO Text -> m Text
forall a b. (a -> b) -> a -> b
$ do
    CString
message' <- Text -> IO CString
textToCString Text
message
    let stripComments' :: CInt
stripComments' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
P.fromIntegral (Int -> CInt) -> (Bool -> Int) -> Bool -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
P.fromEnum) Bool
stripComments
    CString
result <- CString -> CInt -> Int8 -> IO CString
ggit_message_prettify CString
message' CInt
stripComments' Int8
commentChar
    Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"messagePrettify" CString
result
    Text
result' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
result
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
message'
    Text -> IO Text
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result'


-- function init
-- Args: []
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "ggit_init" ggit_init :: 
    IO ()

-- | Call this function before using any other libgit2-glib function.
init ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m ()
init :: forall (m :: * -> *). (HasCallStack, MonadIO m) => m ()
init  = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    IO ()
ggit_init
    () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()


-- function get_features
-- Args: []
-- Lengths: []
-- returnType: Just
--               (TInterface Name { namespace = "Ggit" , name = "FeatureFlags" })
-- throws : False
-- Skip return : False

foreign import ccall "ggit_get_features" ggit_get_features :: 
    IO CUInt

-- | Gets the features of the library.
getFeatures ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m [Ggit.Flags.FeatureFlags]
    -- ^ __Returns:__ a t'GI.Ggit.Flags.FeatureFlags'.
getFeatures :: forall (m :: * -> *). (HasCallStack, MonadIO m) => m [FeatureFlags]
getFeatures  = IO [FeatureFlags] -> m [FeatureFlags]
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [FeatureFlags] -> m [FeatureFlags])
-> IO [FeatureFlags] -> m [FeatureFlags]
forall a b. (a -> b) -> a -> b
$ do
    CUInt
result <- IO CUInt
ggit_get_features
    let result' :: [FeatureFlags]
result' = CUInt -> [FeatureFlags]
forall a b. (Storable a, Integral a, Bits a, IsGFlag b) => a -> [b]
wordToGFlags CUInt
result
    [FeatureFlags] -> IO [FeatureFlags]
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return [FeatureFlags]
result'