{-# LANGUAGE TypeApplications #-}


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

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

module GI.Ggit.Structs.FetchOptions
    (

-- * Exported types
    FetchOptions(..)                        ,
    noFetchOptions                          ,


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

#if defined(ENABLE_OVERLOADING)
    ResolveFetchOptionsMethod               ,
#endif


-- ** copy #method:copy#

#if defined(ENABLE_OVERLOADING)
    FetchOptionsCopyMethodInfo              ,
#endif
    fetchOptionsCopy                        ,


-- ** free #method:free#

#if defined(ENABLE_OVERLOADING)
    FetchOptionsFreeMethodInfo              ,
#endif
    fetchOptionsFree                        ,


-- ** getDownloadTags #method:getDownloadTags#

#if defined(ENABLE_OVERLOADING)
    FetchOptionsGetDownloadTagsMethodInfo   ,
#endif
    fetchOptionsGetDownloadTags             ,


-- ** getRemoteCallbacks #method:getRemoteCallbacks#

#if defined(ENABLE_OVERLOADING)
    FetchOptionsGetRemoteCallbacksMethodInfo,
#endif
    fetchOptionsGetRemoteCallbacks          ,


-- ** new #method:new#

    fetchOptionsNew                         ,


-- ** setDownloadTags #method:setDownloadTags#

#if defined(ENABLE_OVERLOADING)
    FetchOptionsSetDownloadTagsMethodInfo   ,
#endif
    fetchOptionsSetDownloadTags             ,


-- ** setRemoteCallbacks #method:setRemoteCallbacks#

#if defined(ENABLE_OVERLOADING)
    FetchOptionsSetRemoteCallbacksMethodInfo,
#endif
    fetchOptionsSetRemoteCallbacks          ,




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

-- | Memory-managed wrapper type.
newtype FetchOptions = FetchOptions (ManagedPtr FetchOptions)
    deriving (Eq)
foreign import ccall "ggit_fetch_options_get_type" c_ggit_fetch_options_get_type ::
    IO GType

instance BoxedObject FetchOptions where
    boxedType _ = c_ggit_fetch_options_get_type

-- | Convert 'FetchOptions' to and from 'Data.GI.Base.GValue.GValue' with 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue FetchOptions where
    toGValue o = do
        gtype <- c_ggit_fetch_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 FetchOptions)
        B.ManagedPtr.newBoxed FetchOptions ptr



-- | A convenience alias for `Nothing` :: `Maybe` `FetchOptions`.
noFetchOptions :: Maybe FetchOptions
noFetchOptions = Nothing


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

-- method FetchOptions::new
-- method type : Constructor
-- Args: []
-- Lengths: []
-- returnType: Just
--               (TInterface Name { namespace = "Ggit" , name = "FetchOptions" })
-- throws : False
-- Skip return : False

foreign import ccall "ggit_fetch_options_new" ggit_fetch_options_new ::
    IO (Ptr FetchOptions)

-- | Creates a new t'GI.Ggit.Structs.FetchOptions.FetchOptions'.
fetchOptionsNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m FetchOptions
    -- ^ __Returns:__ a newly allocated t'GI.Ggit.Structs.FetchOptions.FetchOptions'.
fetchOptionsNew  = liftIO $ do
    result <- ggit_fetch_options_new
    checkUnexpectedReturnNULL "fetchOptionsNew" result
    result' <- (wrapBoxed FetchOptions) result
    return result'

#if defined(ENABLE_OVERLOADING)
#endif

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

foreign import ccall "ggit_fetch_options_copy" ggit_fetch_options_copy ::
    Ptr FetchOptions ->                     -- fetch_options : TInterface (Name {namespace = "Ggit", name = "FetchOptions"})
    IO (Ptr FetchOptions)

-- | Copies /@fetchOptions@/ into a newly allocated t'GI.Ggit.Structs.FetchOptions.FetchOptions'.
fetchOptionsCopy ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    FetchOptions
    -- ^ /@fetchOptions@/: a t'GI.Ggit.Structs.FetchOptions.FetchOptions'.
    -> m (Maybe FetchOptions)
    -- ^ __Returns:__ a newly allocated t'GI.Ggit.Structs.FetchOptions.FetchOptions' or 'P.Nothing'.
fetchOptionsCopy fetchOptions = liftIO $ do
    fetchOptions' <- unsafeManagedPtrGetPtr fetchOptions
    result <- ggit_fetch_options_copy fetchOptions'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed FetchOptions) result'
        return result''
    touchManagedPtr fetchOptions
    return maybeResult

#if defined(ENABLE_OVERLOADING)
data FetchOptionsCopyMethodInfo
instance (signature ~ (m (Maybe FetchOptions)), MonadIO m) => O.MethodInfo FetchOptionsCopyMethodInfo FetchOptions signature where
    overloadedMethod = fetchOptionsCopy

#endif

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

foreign import ccall "ggit_fetch_options_free" ggit_fetch_options_free ::
    Ptr FetchOptions ->                     -- fetch_options : TInterface (Name {namespace = "Ggit", name = "FetchOptions"})
    IO ()

-- | Frees /@fetchOptions@/.
fetchOptionsFree ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    FetchOptions
    -- ^ /@fetchOptions@/: a t'GI.Ggit.Structs.FetchOptions.FetchOptions'.
    -> m ()
fetchOptionsFree fetchOptions = liftIO $ do
    fetchOptions' <- unsafeManagedPtrGetPtr fetchOptions
    ggit_fetch_options_free fetchOptions'
    touchManagedPtr fetchOptions
    return ()

#if defined(ENABLE_OVERLOADING)
data FetchOptionsFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo FetchOptionsFreeMethodInfo FetchOptions signature where
    overloadedMethod = fetchOptionsFree

#endif

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

foreign import ccall "ggit_fetch_options_get_download_tags" ggit_fetch_options_get_download_tags ::
    Ptr FetchOptions ->                     -- options : TInterface (Name {namespace = "Ggit", name = "FetchOptions"})
    IO CUInt

-- | Get how tags are being handled when fetching\/downloading.
fetchOptionsGetDownloadTags ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    FetchOptions
    -- ^ /@options@/: a t'GI.Ggit.Structs.FetchOptions.FetchOptions'.
    -> m Ggit.Enums.RemoteDownloadTagsType
    -- ^ __Returns:__ a t'GI.Ggit.Enums.RemoteDownloadTagsType'.
fetchOptionsGetDownloadTags options = liftIO $ do
    options' <- unsafeManagedPtrGetPtr options
    result <- ggit_fetch_options_get_download_tags options'
    let result' = (toEnum . fromIntegral) result
    touchManagedPtr options
    return result'

#if defined(ENABLE_OVERLOADING)
data FetchOptionsGetDownloadTagsMethodInfo
instance (signature ~ (m Ggit.Enums.RemoteDownloadTagsType), MonadIO m) => O.MethodInfo FetchOptionsGetDownloadTagsMethodInfo FetchOptions signature where
    overloadedMethod = fetchOptionsGetDownloadTags

#endif

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

foreign import ccall "ggit_fetch_options_get_remote_callbacks" ggit_fetch_options_get_remote_callbacks ::
    Ptr FetchOptions ->                     -- options : TInterface (Name {namespace = "Ggit", name = "FetchOptions"})
    IO (Ptr Ggit.RemoteCallbacks.RemoteCallbacks)

-- | Get the remote callbacks object or 'P.Nothing' if not set.
fetchOptionsGetRemoteCallbacks ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    FetchOptions
    -- ^ /@options@/: a t'GI.Ggit.Structs.FetchOptions.FetchOptions'.
    -> m (Maybe Ggit.RemoteCallbacks.RemoteCallbacks)
    -- ^ __Returns:__ the remote callbacks or 'P.Nothing'.
fetchOptionsGetRemoteCallbacks options = liftIO $ do
    options' <- unsafeManagedPtrGetPtr options
    result <- ggit_fetch_options_get_remote_callbacks options'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (newObject Ggit.RemoteCallbacks.RemoteCallbacks) result'
        return result''
    touchManagedPtr options
    return maybeResult

#if defined(ENABLE_OVERLOADING)
data FetchOptionsGetRemoteCallbacksMethodInfo
instance (signature ~ (m (Maybe Ggit.RemoteCallbacks.RemoteCallbacks)), MonadIO m) => O.MethodInfo FetchOptionsGetRemoteCallbacksMethodInfo FetchOptions signature where
    overloadedMethod = fetchOptionsGetRemoteCallbacks

#endif

-- method FetchOptions::set_download_tags
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "options"
--           , argType =
--               TInterface Name { namespace = "Ggit" , name = "FetchOptions" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GgitFetchOptions."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "download_tags"
--           , argType =
--               TInterface
--                 Name { namespace = "Ggit" , name = "RemoteDownloadTagsType" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GgitRemoteDownloadTagsType."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "ggit_fetch_options_set_download_tags" ggit_fetch_options_set_download_tags ::
    Ptr FetchOptions ->                     -- options : TInterface (Name {namespace = "Ggit", name = "FetchOptions"})
    CUInt ->                                -- download_tags : TInterface (Name {namespace = "Ggit", name = "RemoteDownloadTagsType"})
    IO ()

-- | Set how tags are being handled when fetching\/downloading.
fetchOptionsSetDownloadTags ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    FetchOptions
    -- ^ /@options@/: a t'GI.Ggit.Structs.FetchOptions.FetchOptions'.
    -> Ggit.Enums.RemoteDownloadTagsType
    -- ^ /@downloadTags@/: a t'GI.Ggit.Enums.RemoteDownloadTagsType'.
    -> m ()
fetchOptionsSetDownloadTags options downloadTags = liftIO $ do
    options' <- unsafeManagedPtrGetPtr options
    let downloadTags' = (fromIntegral . fromEnum) downloadTags
    ggit_fetch_options_set_download_tags options' downloadTags'
    touchManagedPtr options
    return ()

#if defined(ENABLE_OVERLOADING)
data FetchOptionsSetDownloadTagsMethodInfo
instance (signature ~ (Ggit.Enums.RemoteDownloadTagsType -> m ()), MonadIO m) => O.MethodInfo FetchOptionsSetDownloadTagsMethodInfo FetchOptions signature where
    overloadedMethod = fetchOptionsSetDownloadTags

#endif

-- method FetchOptions::set_remote_callbacks
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "options"
--           , argType =
--               TInterface Name { namespace = "Ggit" , name = "FetchOptions" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GgitFetchOptions."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "callbacks"
--           , argType =
--               TInterface Name { namespace = "Ggit" , name = "RemoteCallbacks" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GgitRemoteCallbacks or %NULL."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "ggit_fetch_options_set_remote_callbacks" ggit_fetch_options_set_remote_callbacks ::
    Ptr FetchOptions ->                     -- options : TInterface (Name {namespace = "Ggit", name = "FetchOptions"})
    Ptr Ggit.RemoteCallbacks.RemoteCallbacks -> -- callbacks : TInterface (Name {namespace = "Ggit", name = "RemoteCallbacks"})
    IO ()

-- | Set the fetch options object.
fetchOptionsSetRemoteCallbacks ::
    (B.CallStack.HasCallStack, MonadIO m, Ggit.RemoteCallbacks.IsRemoteCallbacks a) =>
    FetchOptions
    -- ^ /@options@/: a t'GI.Ggit.Structs.FetchOptions.FetchOptions'.
    -> Maybe (a)
    -- ^ /@callbacks@/: a t'GI.Ggit.Objects.RemoteCallbacks.RemoteCallbacks' or 'P.Nothing'.
    -> m ()
fetchOptionsSetRemoteCallbacks options callbacks = liftIO $ do
    options' <- unsafeManagedPtrGetPtr options
    maybeCallbacks <- case callbacks of
        Nothing -> return nullPtr
        Just jCallbacks -> do
            jCallbacks' <- unsafeManagedPtrCastPtr jCallbacks
            return jCallbacks'
    ggit_fetch_options_set_remote_callbacks options' maybeCallbacks
    touchManagedPtr options
    whenJust callbacks touchManagedPtr
    return ()

#if defined(ENABLE_OVERLOADING)
data FetchOptionsSetRemoteCallbacksMethodInfo
instance (signature ~ (Maybe (a) -> m ()), MonadIO m, Ggit.RemoteCallbacks.IsRemoteCallbacks a) => O.MethodInfo FetchOptionsSetRemoteCallbacksMethodInfo FetchOptions signature where
    overloadedMethod = fetchOptionsSetRemoteCallbacks

#endif

#if defined(ENABLE_OVERLOADING)
type family ResolveFetchOptionsMethod (t :: Symbol) (o :: *) :: * where
    ResolveFetchOptionsMethod "copy" o = FetchOptionsCopyMethodInfo
    ResolveFetchOptionsMethod "free" o = FetchOptionsFreeMethodInfo
    ResolveFetchOptionsMethod "getDownloadTags" o = FetchOptionsGetDownloadTagsMethodInfo
    ResolveFetchOptionsMethod "getRemoteCallbacks" o = FetchOptionsGetRemoteCallbacksMethodInfo
    ResolveFetchOptionsMethod "setDownloadTags" o = FetchOptionsSetDownloadTagsMethodInfo
    ResolveFetchOptionsMethod "setRemoteCallbacks" o = FetchOptionsSetRemoteCallbacksMethodInfo
    ResolveFetchOptionsMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveFetchOptionsMethod t FetchOptions, O.MethodInfo info FetchOptions p) => OL.IsLabel t (FetchOptions -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#endif