{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- Represents the options used when reverting.

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

module GI.Ggit.Structs.RevertOptions
    (

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


 -- * Methods
-- ** Overloaded methods #method:Overloaded methods#

#if defined(ENABLE_OVERLOADING)
    ResolveRevertOptionsMethod              ,
#endif


-- ** copy #method:copy#

#if defined(ENABLE_OVERLOADING)
    RevertOptionsCopyMethodInfo             ,
#endif
    revertOptionsCopy                       ,


-- ** free #method:free#

#if defined(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.GI.Base.Signals as B.Signals
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)
    deriving (Eq)
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

-- | Convert 'RevertOptions' to and from 'Data.GI.Base.GValue.GValue' with 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue RevertOptions where
    toGValue o = do
        gtype <- c_ggit_revert_options_get_type
        B.ManagedPtr.withManagedPtr o (B.GValue.buildGValue gtype B.GValue.set_boxed)

    fromGValue gv = do
        ptr <- B.GValue.get_boxed gv :: IO (Ptr RevertOptions)
        B.ManagedPtr.newBoxed RevertOptions ptr



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


#if defined(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 t'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 t'GI.Ggit.Structs.MergeOptions.MergeOptions'.
    -> Maybe (a)
    -- ^ /@checkoutOptions@/: a t'GI.Ggit.Objects.CheckoutOptions.CheckoutOptions'.
    -> m (Maybe RevertOptions)
    -- ^ __Returns:__ a t'GI.Ggit.Structs.RevertOptions.RevertOptions' or 'P.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 defined(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 t'GI.Ggit.Structs.RevertOptions.RevertOptions'.
revertOptionsCopy ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    RevertOptions
    -- ^ /@revertOptions@/: a t'GI.Ggit.Structs.RevertOptions.RevertOptions'.
    -> m (Maybe RevertOptions)
    -- ^ __Returns:__ a newly allocated t'GI.Ggit.Structs.RevertOptions.RevertOptions' or 'P.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 defined(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 t'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)
data RevertOptionsFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo RevertOptionsFreeMethodInfo RevertOptions signature where
    overloadedMethod = revertOptionsFree

#endif

#if defined(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 @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#endif