{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)

/No description available in the introspection data./
-}

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

module GI.Soup.Interfaces.ProxyURIResolver
    (

-- * Exported types
    ProxyURIResolver(..)                    ,
    noProxyURIResolver                      ,
    IsProxyURIResolver                      ,
    toProxyURIResolver                      ,


 -- * Methods
-- ** getProxyUriAsync #method:getProxyUriAsync#

#if ENABLE_OVERLOADING
    ProxyURIResolverGetProxyUriAsyncMethodInfo,
#endif
    proxyURIResolverGetProxyUriAsync        ,


-- ** getProxyUriSync #method:getProxyUriSync#

#if ENABLE_OVERLOADING
    ProxyURIResolverGetProxyUriSyncMethodInfo,
#endif
    proxyURIResolverGetProxyUriSync         ,




    ) 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 qualified GI.GLib.Structs.MainContext as GLib.MainContext
import qualified GI.GObject.Objects.Object as GObject.Object
import qualified GI.Gio.Objects.Cancellable as Gio.Cancellable
import qualified GI.Soup.Callbacks as Soup.Callbacks
import {-# SOURCE #-} qualified GI.Soup.Interfaces.SessionFeature as Soup.SessionFeature
import {-# SOURCE #-} qualified GI.Soup.Structs.URI as Soup.URI

-- interface ProxyURIResolver 
-- | Memory-managed wrapper type.
newtype ProxyURIResolver = ProxyURIResolver (ManagedPtr ProxyURIResolver)
-- | A convenience alias for `Nothing` :: `Maybe` `ProxyURIResolver`.
noProxyURIResolver :: Maybe ProxyURIResolver
noProxyURIResolver = Nothing

#if ENABLE_OVERLOADING
type instance O.SignalList ProxyURIResolver = ProxyURIResolverSignalList
type ProxyURIResolverSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

foreign import ccall "soup_proxy_uri_resolver_get_type"
    c_soup_proxy_uri_resolver_get_type :: IO GType

instance GObject ProxyURIResolver where
    gobjectType = c_soup_proxy_uri_resolver_get_type


-- | Type class for types which can be safely cast to `ProxyURIResolver`, for instance with `toProxyURIResolver`.
class (GObject o, O.IsDescendantOf ProxyURIResolver o) => IsProxyURIResolver o
instance (GObject o, O.IsDescendantOf ProxyURIResolver o) => IsProxyURIResolver o

instance O.HasParentTypes ProxyURIResolver
type instance O.ParentTypes ProxyURIResolver = '[Soup.SessionFeature.SessionFeature, GObject.Object.Object]

-- | Cast to `ProxyURIResolver`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toProxyURIResolver :: (MonadIO m, IsProxyURIResolver o) => o -> m ProxyURIResolver
toProxyURIResolver = liftIO . unsafeCastTo ProxyURIResolver

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

#if ENABLE_OVERLOADING
#endif

#if ENABLE_OVERLOADING
type family ResolveProxyURIResolverMethod (t :: Symbol) (o :: *) :: * where
    ResolveProxyURIResolverMethod "addFeature" o = Soup.SessionFeature.SessionFeatureAddFeatureMethodInfo
    ResolveProxyURIResolverMethod "attach" o = Soup.SessionFeature.SessionFeatureAttachMethodInfo
    ResolveProxyURIResolverMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveProxyURIResolverMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveProxyURIResolverMethod "detach" o = Soup.SessionFeature.SessionFeatureDetachMethodInfo
    ResolveProxyURIResolverMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveProxyURIResolverMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveProxyURIResolverMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveProxyURIResolverMethod "hasFeature" o = Soup.SessionFeature.SessionFeatureHasFeatureMethodInfo
    ResolveProxyURIResolverMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveProxyURIResolverMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveProxyURIResolverMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveProxyURIResolverMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveProxyURIResolverMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveProxyURIResolverMethod "removeFeature" o = Soup.SessionFeature.SessionFeatureRemoveFeatureMethodInfo
    ResolveProxyURIResolverMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveProxyURIResolverMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveProxyURIResolverMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveProxyURIResolverMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveProxyURIResolverMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveProxyURIResolverMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveProxyURIResolverMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveProxyURIResolverMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveProxyURIResolverMethod "getProxyUriAsync" o = ProxyURIResolverGetProxyUriAsyncMethodInfo
    ResolveProxyURIResolverMethod "getProxyUriSync" o = ProxyURIResolverGetProxyUriSyncMethodInfo
    ResolveProxyURIResolverMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveProxyURIResolverMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveProxyURIResolverMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveProxyURIResolverMethod l o = O.MethodResolutionFailed l o

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

-- method ProxyURIResolver::get_proxy_uri_async
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "proxy_uri_resolver", argType = TInterface (Name {namespace = "Soup", name = "ProxyURIResolver"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #SoupProxyURIResolver", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "uri", argType = TInterface (Name {namespace = "Soup", name = "URI"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #SoupURI you want a proxy for", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "async_context", argType = TInterface (Name {namespace = "GLib", name = "MainContext"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the #GMainContext to invoke @callback in", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "cancellable", argType = TInterface (Name {namespace = "Gio", name = "Cancellable"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GCancellable, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "callback", argType = TInterface (Name {namespace = "Soup", name = "ProxyURIResolverCallback"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "callback to invoke with the proxy address", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = 5, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "user_data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "data for @callback", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_proxy_uri_resolver_get_proxy_uri_async" soup_proxy_uri_resolver_get_proxy_uri_async ::
    Ptr ProxyURIResolver ->                 -- proxy_uri_resolver : TInterface (Name {namespace = "Soup", name = "ProxyURIResolver"})
    Ptr Soup.URI.URI ->                     -- uri : TInterface (Name {namespace = "Soup", name = "URI"})
    Ptr GLib.MainContext.MainContext ->     -- async_context : TInterface (Name {namespace = "GLib", name = "MainContext"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    FunPtr Soup.Callbacks.C_ProxyURIResolverCallback -> -- callback : TInterface (Name {namespace = "Soup", name = "ProxyURIResolverCallback"})
    Ptr () ->                               -- user_data : TBasicType TPtr
    IO ()

{-# DEPRECATED proxyURIResolverGetProxyUriAsync ["'GI.Soup.Interfaces.ProxyURIResolver.ProxyURIResolver' is deprecated in favor of","'GI.Gio.Interfaces.ProxyResolver.ProxyResolver'"] #-}
{- |
Asynchronously determines a proxy URI to use for /@msg@/ and calls
/@callback@/.

/Since: 2.26.3/
-}
proxyURIResolverGetProxyUriAsync ::
    (B.CallStack.HasCallStack, MonadIO m, IsProxyURIResolver a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@proxyUriResolver@/: the 'GI.Soup.Interfaces.ProxyURIResolver.ProxyURIResolver' -}
    -> Soup.URI.URI
    {- ^ /@uri@/: the 'GI.Soup.Structs.URI.URI' you want a proxy for -}
    -> Maybe (GLib.MainContext.MainContext)
    {- ^ /@asyncContext@/: the 'GI.GLib.Structs.MainContext.MainContext' to invoke /@callback@/ in -}
    -> Maybe (b)
    {- ^ /@cancellable@/: a 'GI.Gio.Objects.Cancellable.Cancellable', or 'Nothing' -}
    -> Soup.Callbacks.ProxyURIResolverCallback
    {- ^ /@callback@/: callback to invoke with the proxy address -}
    -> m ()
proxyURIResolverGetProxyUriAsync proxyUriResolver uri asyncContext cancellable callback = liftIO $ do
    proxyUriResolver' <- unsafeManagedPtrCastPtr proxyUriResolver
    uri' <- unsafeManagedPtrGetPtr uri
    maybeAsyncContext <- case asyncContext of
        Nothing -> return nullPtr
        Just jAsyncContext -> do
            jAsyncContext' <- unsafeManagedPtrGetPtr jAsyncContext
            return jAsyncContext'
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    ptrcallback <- callocMem :: IO (Ptr (FunPtr Soup.Callbacks.C_ProxyURIResolverCallback))
    callback' <- Soup.Callbacks.mk_ProxyURIResolverCallback (Soup.Callbacks.wrap_ProxyURIResolverCallback (Just ptrcallback) (Soup.Callbacks.drop_closures_ProxyURIResolverCallback callback))
    poke ptrcallback callback'
    let userData = nullPtr
    soup_proxy_uri_resolver_get_proxy_uri_async proxyUriResolver' uri' maybeAsyncContext maybeCancellable callback' userData
    touchManagedPtr proxyUriResolver
    touchManagedPtr uri
    whenJust asyncContext touchManagedPtr
    whenJust cancellable touchManagedPtr
    return ()

#if ENABLE_OVERLOADING
data ProxyURIResolverGetProxyUriAsyncMethodInfo
instance (signature ~ (Soup.URI.URI -> Maybe (GLib.MainContext.MainContext) -> Maybe (b) -> Soup.Callbacks.ProxyURIResolverCallback -> m ()), MonadIO m, IsProxyURIResolver a, Gio.Cancellable.IsCancellable b) => O.MethodInfo ProxyURIResolverGetProxyUriAsyncMethodInfo a signature where
    overloadedMethod _ = proxyURIResolverGetProxyUriAsync

#endif

-- method ProxyURIResolver::get_proxy_uri_sync
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "proxy_uri_resolver", argType = TInterface (Name {namespace = "Soup", name = "ProxyURIResolver"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #SoupProxyURIResolver", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "uri", argType = TInterface (Name {namespace = "Soup", name = "URI"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #SoupURI you want a proxy for", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "cancellable", argType = TInterface (Name {namespace = "Gio", name = "Cancellable"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GCancellable, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "proxy_uri", argType = TInterface (Name {namespace = "Soup", name = "URI"}), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "on return, will contain the proxy URI", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt)
-- throws : False
-- Skip return : False

foreign import ccall "soup_proxy_uri_resolver_get_proxy_uri_sync" soup_proxy_uri_resolver_get_proxy_uri_sync ::
    Ptr ProxyURIResolver ->                 -- proxy_uri_resolver : TInterface (Name {namespace = "Soup", name = "ProxyURIResolver"})
    Ptr Soup.URI.URI ->                     -- uri : TInterface (Name {namespace = "Soup", name = "URI"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr (Ptr Soup.URI.URI) ->               -- proxy_uri : TInterface (Name {namespace = "Soup", name = "URI"})
    IO Word32

{-# DEPRECATED proxyURIResolverGetProxyUriSync ["'GI.Soup.Interfaces.ProxyURIResolver.ProxyURIResolver' is deprecated in favor of","'GI.Gio.Interfaces.ProxyResolver.ProxyResolver'"] #-}
{- |
Synchronously determines a proxy URI to use for /@uri@/. If /@uri@/
should be sent via proxy, */@proxyUri@/ will be set to the URI of the
proxy, else it will be set to 'Nothing'.

/Since: 2.26.3/
-}
proxyURIResolverGetProxyUriSync ::
    (B.CallStack.HasCallStack, MonadIO m, IsProxyURIResolver a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@proxyUriResolver@/: the 'GI.Soup.Interfaces.ProxyURIResolver.ProxyURIResolver' -}
    -> Soup.URI.URI
    {- ^ /@uri@/: the 'GI.Soup.Structs.URI.URI' you want a proxy for -}
    -> Maybe (b)
    {- ^ /@cancellable@/: a 'GI.Gio.Objects.Cancellable.Cancellable', or 'Nothing' -}
    -> m ((Word32, Soup.URI.URI))
    {- ^ __Returns:__ 'GI.Soup.Enums.StatusOk' if successful, or a transport-level
error. -}
proxyURIResolverGetProxyUriSync proxyUriResolver uri cancellable = liftIO $ do
    proxyUriResolver' <- unsafeManagedPtrCastPtr proxyUriResolver
    uri' <- unsafeManagedPtrGetPtr uri
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    proxyUri <- allocMem :: IO (Ptr (Ptr Soup.URI.URI))
    result <- soup_proxy_uri_resolver_get_proxy_uri_sync proxyUriResolver' uri' maybeCancellable proxyUri
    proxyUri' <- peek proxyUri
    proxyUri'' <- (wrapBoxed Soup.URI.URI) proxyUri'
    touchManagedPtr proxyUriResolver
    touchManagedPtr uri
    whenJust cancellable touchManagedPtr
    freeMem proxyUri
    return (result, proxyUri'')

#if ENABLE_OVERLOADING
data ProxyURIResolverGetProxyUriSyncMethodInfo
instance (signature ~ (Soup.URI.URI -> Maybe (b) -> m ((Word32, Soup.URI.URI))), MonadIO m, IsProxyURIResolver a, Gio.Cancellable.IsCancellable b) => O.MethodInfo ProxyURIResolverGetProxyUriSyncMethodInfo a signature where
    overloadedMethod _ = proxyURIResolverGetProxyUriSync

#endif