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

module GI.Ggit.Structs.RevertOptions
    ( 

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


 -- * Methods
-- ** copy #method:copy#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    RevertOptionsCopyMethodInfo             ,
#endif
    revertOptionsCopy                       ,


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

import {-# SOURCE #-} qualified GI.Ggit.Objects.CheckoutOptions as Ggit.CheckoutOptions
import {-# SOURCE #-} qualified GI.Ggit.Structs.MergeOptions as Ggit.MergeOptions

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

noRevertOptions :: Maybe RevertOptions
noRevertOptions = Nothing


#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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 RevertOptions
    {- ^ __Returns:__ a 'GI.Ggit.Structs.RevertOptions.RevertOptions'. -}
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
    checkUnexpectedReturnNULL "revertOptionsNew" result
    result' <- (wrapBoxed RevertOptions) result
    whenJust mergeOptions touchManagedPtr
    whenJust checkoutOptions touchManagedPtr
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
#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 RevertOptions
    {- ^ __Returns:__ a newly allocated 'GI.Ggit.Structs.RevertOptions.RevertOptions'. -}
revertOptionsCopy revertOptions = liftIO $ do
    revertOptions' <- unsafeManagedPtrGetPtr revertOptions
    result <- ggit_revert_options_copy revertOptions'
    checkUnexpectedReturnNULL "revertOptionsCopy" result
    result' <- (wrapBoxed RevertOptions) result
    touchManagedPtr revertOptions
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data RevertOptionsCopyMethodInfo
instance (signature ~ (m 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 defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data RevertOptionsFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo RevertOptionsFreeMethodInfo RevertOptions signature where
    overloadedMethod _ = revertOptionsFree

#endif

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

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

#endif