{- |
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 options used when reverting.
-}

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

module GI.Ggit.Structs.RevertOptions
    (

-- * Exported types
    RevertOptions(..)                       ,
    noRevertOptions                         ,


 -- * Methods
-- ** copy #method:copy#

#if ENABLE_OVERLOADING
    RevertOptionsCopyMethodInfo             ,
#endif
    revertOptionsCopy                       ,


-- ** free #method:free#

#if ENABLE_OVERLOADING
    RevertOptionsFreeMethodInfo             ,
#endif
    revertOptionsFree                       ,


-- ** new #method:new#

    revertOptionsNew                        ,




    ) 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.Objects.CheckoutOptions as Ggit.CheckoutOptions
import {-# SOURCE #-} qualified GI.Ggit.Structs.MergeOptions as Ggit.MergeOptions

-- | Memory-managed wrapper type.
newtype RevertOptions = RevertOptions (ManagedPtr RevertOptions)
foreign import ccall "ggit_revert_options_get_type" c_ggit_revert_options_get_type ::
    IO GType

instance BoxedObject RevertOptions where
    boxedType _ = c_ggit_revert_options_get_type

-- | A convenience alias for `Nothing` :: `Maybe` `RevertOptions`.
noRevertOptions :: Maybe RevertOptions
noRevertOptions = Nothing


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

-- method RevertOptions::new
-- method type : Constructor
-- Args : [Arg {argCName = "mainline", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the mainline.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "merge_options", argType = TInterface (Name {namespace = "Ggit", name = "MergeOptions"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GgitMergeOptions.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "checkout_options", argType = TInterface (Name {namespace = "Ggit", name = "CheckoutOptions"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GgitCheckoutOptions.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "RevertOptions"}))
-- throws : False
-- Skip return : False

foreign import ccall "ggit_revert_options_new" ggit_revert_options_new ::
    Word32 ->                               -- mainline : TBasicType TUInt
    Ptr Ggit.MergeOptions.MergeOptions ->   -- merge_options : TInterface (Name {namespace = "Ggit", name = "MergeOptions"})
    Ptr Ggit.CheckoutOptions.CheckoutOptions -> -- checkout_options : TInterface (Name {namespace = "Ggit", name = "CheckoutOptions"})
    IO (Ptr RevertOptions)

{- |
Create a new 'GI.Ggit.Structs.RevertOptions.RevertOptions'. Note that the passed in /@mergeOptions@/ and
/@checkoutOptions@/ are copied by this function, and alterations in either
after this call are therefore not reflected in the revert options.

The /@mainline@/ indicates which parent to use for the revert when reverting
a merge commit.
-}
revertOptionsNew ::
    (B.CallStack.HasCallStack, MonadIO m, Ggit.CheckoutOptions.IsCheckoutOptions a) =>
    Word32
    {- ^ /@mainline@/: the mainline. -}
    -> Maybe (Ggit.MergeOptions.MergeOptions)
    {- ^ /@mergeOptions@/: a 'GI.Ggit.Structs.MergeOptions.MergeOptions'. -}
    -> Maybe (a)
    {- ^ /@checkoutOptions@/: a 'GI.Ggit.Objects.CheckoutOptions.CheckoutOptions'. -}
    -> m (Maybe RevertOptions)
    {- ^ __Returns:__ a 'GI.Ggit.Structs.RevertOptions.RevertOptions' or 'Nothing'. -}
revertOptionsNew mainline mergeOptions checkoutOptions = liftIO $ do
    maybeMergeOptions <- case mergeOptions of
        Nothing -> return nullPtr
        Just jMergeOptions -> do
            jMergeOptions' <- unsafeManagedPtrGetPtr jMergeOptions
            return jMergeOptions'
    maybeCheckoutOptions <- case checkoutOptions of
        Nothing -> return nullPtr
        Just jCheckoutOptions -> do
            jCheckoutOptions' <- unsafeManagedPtrCastPtr jCheckoutOptions
            return jCheckoutOptions'
    result <- ggit_revert_options_new mainline maybeMergeOptions maybeCheckoutOptions
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed RevertOptions) result'
        return result''
    whenJust mergeOptions touchManagedPtr
    whenJust checkoutOptions touchManagedPtr
    return maybeResult

#if ENABLE_OVERLOADING
#endif

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

foreign import ccall "ggit_revert_options_copy" ggit_revert_options_copy ::
    Ptr RevertOptions ->                    -- revert_options : TInterface (Name {namespace = "Ggit", name = "RevertOptions"})
    IO (Ptr RevertOptions)

{- |
Copies /@revertOptions@/ into a newly allocated 'GI.Ggit.Structs.RevertOptions.RevertOptions'.
-}
revertOptionsCopy ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    RevertOptions
    {- ^ /@revertOptions@/: a 'GI.Ggit.Structs.RevertOptions.RevertOptions'. -}
    -> m (Maybe RevertOptions)
    {- ^ __Returns:__ a newly allocated 'GI.Ggit.Structs.RevertOptions.RevertOptions' or 'Nothing'. -}
revertOptionsCopy revertOptions = liftIO $ do
    revertOptions' <- unsafeManagedPtrGetPtr revertOptions
    result <- ggit_revert_options_copy revertOptions'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed RevertOptions) result'
        return result''
    touchManagedPtr revertOptions
    return maybeResult

#if ENABLE_OVERLOADING
data RevertOptionsCopyMethodInfo
instance (signature ~ (m (Maybe RevertOptions)), MonadIO m) => O.MethodInfo RevertOptionsCopyMethodInfo RevertOptions signature where
    overloadedMethod _ = revertOptionsCopy

#endif

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

foreign import ccall "ggit_revert_options_free" ggit_revert_options_free ::
    Ptr RevertOptions ->                    -- revert_options : TInterface (Name {namespace = "Ggit", name = "RevertOptions"})
    IO ()

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

#if ENABLE_OVERLOADING
data RevertOptionsFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo RevertOptionsFreeMethodInfo RevertOptions signature where
    overloadedMethod _ = revertOptionsFree

#endif

#if ENABLE_OVERLOADING
type family ResolveRevertOptionsMethod (t :: Symbol) (o :: *) :: * where
    ResolveRevertOptionsMethod "copy" o = RevertOptionsCopyMethodInfo
    ResolveRevertOptionsMethod "free" o = RevertOptionsFreeMethodInfo
    ResolveRevertOptionsMethod l o = O.MethodResolutionFailed l o

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