{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)
-}

module GI.WebKit2.Structs.Credential
    ( 

-- * Exported types
    Credential(..)                          ,
    noCredential                            ,


 -- * Methods
-- ** copy #method:copy#
    CredentialCopyMethodInfo                ,
    credentialCopy                          ,


-- ** free #method:free#
    CredentialFreeMethodInfo                ,
    credentialFree                          ,


-- ** getPassword #method:getPassword#
    CredentialGetPasswordMethodInfo         ,
    credentialGetPassword                   ,


-- ** getPersistence #method:getPersistence#
    CredentialGetPersistenceMethodInfo      ,
    credentialGetPersistence                ,


-- ** getUsername #method:getUsername#
    CredentialGetUsernameMethodInfo         ,
    credentialGetUsername                   ,


-- ** hasPassword #method:hasPassword#
    CredentialHasPasswordMethodInfo         ,
    credentialHasPassword                   ,


-- ** new #method:new#
    credentialNew                           ,




    ) 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.WebKit2.Enums as WebKit2.Enums

newtype Credential = Credential (ManagedPtr Credential)
foreign import ccall "webkit_credential_get_type" c_webkit_credential_get_type :: 
    IO GType

instance BoxedObject Credential where
    boxedType _ = c_webkit_credential_get_type

noCredential :: Maybe Credential
noCredential = Nothing


instance O.HasAttributeList Credential
type instance O.AttributeList Credential = CredentialAttributeList
type CredentialAttributeList = ('[ ] :: [(Symbol, *)])

-- method Credential::new
-- method type : Constructor
-- Args : [Arg {argCName = "username", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The username for the new credential", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "password", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The password for the new credential", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "persistence", argType = TInterface (Name {namespace = "WebKit2", name = "CredentialPersistence"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The #WebKitCredentialPersistence of the new credential", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "WebKit2", name = "Credential"}))
-- throws : False
-- Skip return : False

foreign import ccall "webkit_credential_new" webkit_credential_new :: 
    CString ->                              -- username : TBasicType TUTF8
    CString ->                              -- password : TBasicType TUTF8
    CUInt ->                                -- persistence : TInterface (Name {namespace = "WebKit2", name = "CredentialPersistence"})
    IO (Ptr Credential)

{- |
Create a new credential from the provided username, password and persistence mode.

@since 2.2
-}
credentialNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@username@/: The username for the new credential -}
    -> T.Text
    {- ^ /@password@/: The password for the new credential -}
    -> WebKit2.Enums.CredentialPersistence
    {- ^ /@persistence@/: The 'GI.WebKit2.Enums.CredentialPersistence' of the new credential -}
    -> m Credential
    {- ^ __Returns:__ A 'GI.WebKit2.Structs.Credential.Credential'. -}
credentialNew username password persistence = liftIO $ do
    username' <- textToCString username
    password' <- textToCString password
    let persistence' = (fromIntegral . fromEnum) persistence
    result <- webkit_credential_new username' password' persistence'
    checkUnexpectedReturnNULL "credentialNew" result
    result' <- (wrapBoxed Credential) result
    freeMem username'
    freeMem password'
    return result'

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

foreign import ccall "webkit_credential_copy" webkit_credential_copy :: 
    Ptr Credential ->                       -- credential : TInterface (Name {namespace = "WebKit2", name = "Credential"})
    IO (Ptr Credential)

{- |
Make a copy of the 'GI.WebKit2.Structs.Credential.Credential'.

@since 2.2
-}
credentialCopy ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Credential
    {- ^ /@credential@/: a 'GI.WebKit2.Structs.Credential.Credential' -}
    -> m Credential
    {- ^ __Returns:__ A copy of passed in 'GI.WebKit2.Structs.Credential.Credential' -}
credentialCopy credential = liftIO $ do
    credential' <- unsafeManagedPtrGetPtr credential
    result <- webkit_credential_copy credential'
    checkUnexpectedReturnNULL "credentialCopy" result
    result' <- (wrapBoxed Credential) result
    touchManagedPtr credential
    return result'

data CredentialCopyMethodInfo
instance (signature ~ (m Credential), MonadIO m) => O.MethodInfo CredentialCopyMethodInfo Credential signature where
    overloadedMethod _ = credentialCopy

-- method Credential::free
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "credential", argType = TInterface (Name {namespace = "WebKit2", name = "Credential"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #WebKitCredential", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "webkit_credential_free" webkit_credential_free :: 
    Ptr Credential ->                       -- credential : TInterface (Name {namespace = "WebKit2", name = "Credential"})
    IO ()

{- |
Free the 'GI.WebKit2.Structs.Credential.Credential'.

@since 2.2
-}
credentialFree ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Credential
    {- ^ /@credential@/: A 'GI.WebKit2.Structs.Credential.Credential' -}
    -> m ()
credentialFree credential = liftIO $ do
    credential' <- unsafeManagedPtrGetPtr credential
    webkit_credential_free credential'
    touchManagedPtr credential
    return ()

data CredentialFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo CredentialFreeMethodInfo Credential signature where
    overloadedMethod _ = credentialFree

-- method Credential::get_password
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "credential", argType = TInterface (Name {namespace = "WebKit2", name = "Credential"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitCredential", 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 "webkit_credential_get_password" webkit_credential_get_password :: 
    Ptr Credential ->                       -- credential : TInterface (Name {namespace = "WebKit2", name = "Credential"})
    IO CString

{- |
Get the password currently held by this 'GI.WebKit2.Structs.Credential.Credential'.

@since 2.2
-}
credentialGetPassword ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Credential
    {- ^ /@credential@/: a 'GI.WebKit2.Structs.Credential.Credential' -}
    -> m T.Text
    {- ^ __Returns:__ The password stored in the 'GI.WebKit2.Structs.Credential.Credential'. -}
credentialGetPassword credential = liftIO $ do
    credential' <- unsafeManagedPtrGetPtr credential
    result <- webkit_credential_get_password credential'
    checkUnexpectedReturnNULL "credentialGetPassword" result
    result' <- cstringToText result
    touchManagedPtr credential
    return result'

data CredentialGetPasswordMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.MethodInfo CredentialGetPasswordMethodInfo Credential signature where
    overloadedMethod _ = credentialGetPassword

-- method Credential::get_persistence
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "credential", argType = TInterface (Name {namespace = "WebKit2", name = "Credential"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitCredential", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "WebKit2", name = "CredentialPersistence"}))
-- throws : False
-- Skip return : False

foreign import ccall "webkit_credential_get_persistence" webkit_credential_get_persistence :: 
    Ptr Credential ->                       -- credential : TInterface (Name {namespace = "WebKit2", name = "Credential"})
    IO CUInt

{- |
Get the persistence mode currently held by this 'GI.WebKit2.Structs.Credential.Credential'.

@since 2.2
-}
credentialGetPersistence ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Credential
    {- ^ /@credential@/: a 'GI.WebKit2.Structs.Credential.Credential' -}
    -> m WebKit2.Enums.CredentialPersistence
    {- ^ __Returns:__ The 'GI.WebKit2.Enums.CredentialPersistence' stored in the 'GI.WebKit2.Structs.Credential.Credential'. -}
credentialGetPersistence credential = liftIO $ do
    credential' <- unsafeManagedPtrGetPtr credential
    result <- webkit_credential_get_persistence credential'
    let result' = (toEnum . fromIntegral) result
    touchManagedPtr credential
    return result'

data CredentialGetPersistenceMethodInfo
instance (signature ~ (m WebKit2.Enums.CredentialPersistence), MonadIO m) => O.MethodInfo CredentialGetPersistenceMethodInfo Credential signature where
    overloadedMethod _ = credentialGetPersistence

-- method Credential::get_username
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "credential", argType = TInterface (Name {namespace = "WebKit2", name = "Credential"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitCredential", 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 "webkit_credential_get_username" webkit_credential_get_username :: 
    Ptr Credential ->                       -- credential : TInterface (Name {namespace = "WebKit2", name = "Credential"})
    IO CString

{- |
Get the username currently held by this 'GI.WebKit2.Structs.Credential.Credential'.

@since 2.2
-}
credentialGetUsername ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Credential
    {- ^ /@credential@/: a 'GI.WebKit2.Structs.Credential.Credential' -}
    -> m T.Text
    {- ^ __Returns:__ The username stored in the 'GI.WebKit2.Structs.Credential.Credential'. -}
credentialGetUsername credential = liftIO $ do
    credential' <- unsafeManagedPtrGetPtr credential
    result <- webkit_credential_get_username credential'
    checkUnexpectedReturnNULL "credentialGetUsername" result
    result' <- cstringToText result
    touchManagedPtr credential
    return result'

data CredentialGetUsernameMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.MethodInfo CredentialGetUsernameMethodInfo Credential signature where
    overloadedMethod _ = credentialGetUsername

-- method Credential::has_password
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "credential", argType = TInterface (Name {namespace = "WebKit2", name = "Credential"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitCredential", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "webkit_credential_has_password" webkit_credential_has_password :: 
    Ptr Credential ->                       -- credential : TInterface (Name {namespace = "WebKit2", name = "Credential"})
    IO CInt

{- |
Determine whether this credential has a password stored.

@since 2.2
-}
credentialHasPassword ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Credential
    {- ^ /@credential@/: a 'GI.WebKit2.Structs.Credential.Credential' -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the credential has a password or 'False' otherwise. -}
credentialHasPassword credential = liftIO $ do
    credential' <- unsafeManagedPtrGetPtr credential
    result <- webkit_credential_has_password credential'
    let result' = (/= 0) result
    touchManagedPtr credential
    return result'

data CredentialHasPasswordMethodInfo
instance (signature ~ (m Bool), MonadIO m) => O.MethodInfo CredentialHasPasswordMethodInfo Credential signature where
    overloadedMethod _ = credentialHasPassword

type family ResolveCredentialMethod (t :: Symbol) (o :: *) :: * where
    ResolveCredentialMethod "copy" o = CredentialCopyMethodInfo
    ResolveCredentialMethod "free" o = CredentialFreeMethodInfo
    ResolveCredentialMethod "hasPassword" o = CredentialHasPasswordMethodInfo
    ResolveCredentialMethod "getPassword" o = CredentialGetPasswordMethodInfo
    ResolveCredentialMethod "getPersistence" o = CredentialGetPersistenceMethodInfo
    ResolveCredentialMethod "getUsername" o = CredentialGetUsernameMethodInfo
    ResolveCredentialMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveCredentialMethod t Credential, O.MethodInfo info Credential p) => O.IsLabelProxy t (Credential -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveCredentialMethod t Credential, O.MethodInfo info Credential p) => O.IsLabel t (Credential -> p) where
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif