{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- This represents the configuration for a single remote repository. Currently,
-- remotes can only be passed around as (reference counted) opaque handles. In
-- future, more API may be added to create and interrogate them.
-- 
-- /Since: 2018.6/

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

module GI.OSTree.Structs.Remote
    ( 

-- * Exported types
    Remote(..)                              ,
    noRemote                                ,


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

#if defined(ENABLE_OVERLOADING)
    ResolveRemoteMethod                     ,
#endif


-- ** getName #method:getName#

#if defined(ENABLE_OVERLOADING)
    RemoteGetNameMethodInfo                 ,
#endif
    remoteGetName                           ,


-- ** getUrl #method:getUrl#

#if defined(ENABLE_OVERLOADING)
    RemoteGetUrlMethodInfo                  ,
#endif
    remoteGetUrl                            ,


-- ** ref #method:ref#

#if defined(ENABLE_OVERLOADING)
    RemoteRefMethodInfo                     ,
#endif
    remoteRef                               ,


-- ** unref #method:unref#

#if defined(ENABLE_OVERLOADING)
    RemoteUnrefMethodInfo                   ,
#endif
    remoteUnref                             ,




    ) 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


-- | Memory-managed wrapper type.
newtype Remote = Remote (ManagedPtr Remote)
    deriving (Remote -> Remote -> Bool
(Remote -> Remote -> Bool)
-> (Remote -> Remote -> Bool) -> Eq Remote
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Remote -> Remote -> Bool
$c/= :: Remote -> Remote -> Bool
== :: Remote -> Remote -> Bool
$c== :: Remote -> Remote -> Bool
Eq)
foreign import ccall "ostree_remote_get_type" c_ostree_remote_get_type :: 
    IO GType

instance BoxedObject Remote where
    boxedType :: Remote -> IO GType
boxedType _ = IO GType
c_ostree_remote_get_type

-- | Convert 'Remote' to and from 'Data.GI.Base.GValue.GValue' with 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue Remote where
    toGValue :: Remote -> IO GValue
toGValue o :: Remote
o = do
        GType
gtype <- IO GType
c_ostree_remote_get_type
        Remote -> (Ptr Remote -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Remote
o (GType -> (GValue -> Ptr Remote -> IO ()) -> Ptr Remote -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr Remote -> IO ()
forall a. GValue -> Ptr a -> IO ()
B.GValue.set_boxed)
        
    fromGValue :: GValue -> IO Remote
fromGValue gv :: GValue
gv = do
        Ptr Remote
ptr <- GValue -> IO (Ptr Remote)
forall b. GValue -> IO (Ptr b)
B.GValue.get_boxed GValue
gv :: IO (Ptr Remote)
        (ManagedPtr Remote -> Remote) -> Ptr Remote -> IO Remote
forall a.
(HasCallStack, BoxedObject a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
B.ManagedPtr.newBoxed ManagedPtr Remote -> Remote
Remote Ptr Remote
ptr
        
    

-- | A convenience alias for `Nothing` :: `Maybe` `Remote`.
noRemote :: Maybe Remote
noRemote :: Maybe Remote
noRemote = Maybe Remote
forall a. Maybe a
Nothing


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

-- method Remote::get_name
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "remote"
--           , argType =
--               TInterface Name { namespace = "OSTree" , name = "Remote" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "an #OstreeRemote" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "ostree_remote_get_name" ostree_remote_get_name :: 
    Ptr Remote ->                           -- remote : TInterface (Name {namespace = "OSTree", name = "Remote"})
    IO CString

-- | Get the human-readable name of the remote. This is what the user configured,
-- if the remote was explicitly configured; and will otherwise be a stable,
-- arbitrary, string.
-- 
-- /Since: 2018.6/
remoteGetName ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Remote
    -- ^ /@remote@/: an t'GI.OSTree.Structs.Remote.Remote'
    -> m T.Text
    -- ^ __Returns:__ remote’s name
remoteGetName :: Remote -> m Text
remoteGetName remote :: Remote
remote = IO Text -> m Text
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Text -> m Text) -> IO Text -> m Text
forall a b. (a -> b) -> a -> b
$ do
    Ptr Remote
remote' <- Remote -> IO (Ptr Remote)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Remote
remote
    CString
result <- Ptr Remote -> IO CString
ostree_remote_get_name Ptr Remote
remote'
    Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "remoteGetName" CString
result
    Text
result' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result
    Remote -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Remote
remote
    Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result'

#if defined(ENABLE_OVERLOADING)
data RemoteGetNameMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.MethodInfo RemoteGetNameMethodInfo Remote signature where
    overloadedMethod = remoteGetName

#endif

-- method Remote::get_url
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "remote"
--           , argType =
--               TInterface Name { namespace = "OSTree" , name = "Remote" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "an #OstreeRemote" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "ostree_remote_get_url" ostree_remote_get_url :: 
    Ptr Remote ->                           -- remote : TInterface (Name {namespace = "OSTree", name = "Remote"})
    IO CString

-- | Get the URL from the remote.
-- 
-- /Since: 2018.6/
remoteGetUrl ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Remote
    -- ^ /@remote@/: an t'GI.OSTree.Structs.Remote.Remote'
    -> m T.Text
    -- ^ __Returns:__ the remote\'s URL
remoteGetUrl :: Remote -> m Text
remoteGetUrl remote :: Remote
remote = IO Text -> m Text
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Text -> m Text) -> IO Text -> m Text
forall a b. (a -> b) -> a -> b
$ do
    Ptr Remote
remote' <- Remote -> IO (Ptr Remote)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Remote
remote
    CString
result <- Ptr Remote -> IO CString
ostree_remote_get_url Ptr Remote
remote'
    Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "remoteGetUrl" CString
result
    Text
result' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
result
    Remote -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Remote
remote
    Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result'

#if defined(ENABLE_OVERLOADING)
data RemoteGetUrlMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.MethodInfo RemoteGetUrlMethodInfo Remote signature where
    overloadedMethod = remoteGetUrl

#endif

-- method Remote::ref
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "remote"
--           , argType =
--               TInterface Name { namespace = "OSTree" , name = "Remote" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "an #OstreeRemote" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "OSTree" , name = "Remote" })
-- throws : False
-- Skip return : False

foreign import ccall "ostree_remote_ref" ostree_remote_ref :: 
    Ptr Remote ->                           -- remote : TInterface (Name {namespace = "OSTree", name = "Remote"})
    IO (Ptr Remote)

-- | Increase the reference count on the given /@remote@/.
-- 
-- /Since: 2018.6/
remoteRef ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Remote
    -- ^ /@remote@/: an t'GI.OSTree.Structs.Remote.Remote'
    -> m Remote
    -- ^ __Returns:__ a copy of /@remote@/, for convenience
remoteRef :: Remote -> m Remote
remoteRef remote :: Remote
remote = IO Remote -> m Remote
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Remote -> m Remote) -> IO Remote -> m Remote
forall a b. (a -> b) -> a -> b
$ do
    Ptr Remote
remote' <- Remote -> IO (Ptr Remote)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Remote
remote
    Ptr Remote
result <- Ptr Remote -> IO (Ptr Remote)
ostree_remote_ref Ptr Remote
remote'
    Text -> Ptr Remote -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "remoteRef" Ptr Remote
result
    Remote
result' <- ((ManagedPtr Remote -> Remote) -> Ptr Remote -> IO Remote
forall a.
(HasCallStack, BoxedObject a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Remote -> Remote
Remote) Ptr Remote
result
    Remote -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Remote
remote
    Remote -> IO Remote
forall (m :: * -> *) a. Monad m => a -> m a
return Remote
result'

#if defined(ENABLE_OVERLOADING)
data RemoteRefMethodInfo
instance (signature ~ (m Remote), MonadIO m) => O.MethodInfo RemoteRefMethodInfo Remote signature where
    overloadedMethod = remoteRef

#endif

-- method Remote::unref
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "remote"
--           , argType =
--               TInterface Name { namespace = "OSTree" , name = "Remote" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "an #OstreeRemote" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "ostree_remote_unref" ostree_remote_unref :: 
    Ptr Remote ->                           -- remote : TInterface (Name {namespace = "OSTree", name = "Remote"})
    IO ()

-- | Decrease the reference count on the given /@remote@/ and free it if the
-- reference count reaches 0.
-- 
-- /Since: 2018.6/
remoteUnref ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Remote
    -- ^ /@remote@/: an t'GI.OSTree.Structs.Remote.Remote'
    -> m ()
remoteUnref :: Remote -> m ()
remoteUnref remote :: Remote
remote = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Remote
remote' <- Remote -> IO (Ptr Remote)
forall a. (HasCallStack, BoxedObject a) => a -> IO (Ptr a)
B.ManagedPtr.disownBoxed Remote
remote
    Ptr Remote -> IO ()
ostree_remote_unref Ptr Remote
remote'
    Remote -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Remote
remote
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data RemoteUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo RemoteUnrefMethodInfo Remote signature where
    overloadedMethod = remoteUnref

#endif

#if defined(ENABLE_OVERLOADING)
type family ResolveRemoteMethod (t :: Symbol) (o :: *) :: * where
    ResolveRemoteMethod "ref" o = RemoteRefMethodInfo
    ResolveRemoteMethod "unref" o = RemoteUnrefMethodInfo
    ResolveRemoteMethod "getName" o = RemoteGetNameMethodInfo
    ResolveRemoteMethod "getUrl" o = RemoteGetUrlMethodInfo
    ResolveRemoteMethod l o = O.MethodResolutionFailed l o

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

#endif