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

Represents an action signature.
-}

module GI.Ggit.Objects.Signature
    ( 

-- * Exported types
    Signature(..)                           ,
    IsSignature                             ,
    toSignature                             ,
    noSignature                             ,


 -- * Methods
-- ** copy #method:copy#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    SignatureCopyMethodInfo                 ,
#endif
    signatureCopy                           ,


-- ** getEmail #method:getEmail#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    SignatureGetEmailMethodInfo             ,
#endif
    signatureGetEmail                       ,


-- ** getName #method:getName#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    SignatureGetNameMethodInfo              ,
#endif
    signatureGetName                        ,


-- ** getTime #method:getTime#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    SignatureGetTimeMethodInfo              ,
#endif
    signatureGetTime                        ,


-- ** getTimeZone #method:getTimeZone#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    SignatureGetTimeZoneMethodInfo          ,
#endif
    signatureGetTimeZone                    ,


-- ** new #method:new#
    signatureNew                            ,


-- ** newNow #method:newNow#
    signatureNewNow                         ,




 -- * Properties
-- ** encoding #attr:encoding#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    SignatureEncodingPropertyInfo           ,
#endif
    constructSignatureEncoding              ,
    getSignatureEncoding                    ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    signatureEncoding                       ,
#endif




    ) 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 qualified GI.GLib.Structs.DateTime as GLib.DateTime
import qualified GI.GLib.Structs.TimeZone as GLib.TimeZone
import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Ggit.Objects.Native as Ggit.Native
import {-# SOURCE #-} qualified GI.Ggit.Objects.ObjectFactoryBase as Ggit.ObjectFactoryBase

newtype Signature = Signature (ManagedPtr Signature)
foreign import ccall "ggit_signature_get_type"
    c_ggit_signature_get_type :: IO GType

instance GObject Signature where
    gobjectType _ = c_ggit_signature_get_type
    

class GObject o => IsSignature o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError Signature a) =>
    IsSignature a
#endif
instance IsSignature Signature
instance Ggit.Native.IsNative Signature
instance Ggit.ObjectFactoryBase.IsObjectFactoryBase Signature
instance GObject.Object.IsObject Signature

toSignature :: (MonadIO m, IsSignature o) => o -> m Signature
toSignature = liftIO . unsafeCastTo Signature

noSignature :: Maybe Signature
noSignature = Nothing

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type family ResolveSignatureMethod (t :: Symbol) (o :: *) :: * where
    ResolveSignatureMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveSignatureMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveSignatureMethod "copy" o = SignatureCopyMethodInfo
    ResolveSignatureMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveSignatureMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveSignatureMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveSignatureMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveSignatureMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveSignatureMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveSignatureMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveSignatureMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveSignatureMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveSignatureMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveSignatureMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveSignatureMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveSignatureMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveSignatureMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveSignatureMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveSignatureMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveSignatureMethod "getEmail" o = SignatureGetEmailMethodInfo
    ResolveSignatureMethod "getName" o = SignatureGetNameMethodInfo
    ResolveSignatureMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveSignatureMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveSignatureMethod "getTime" o = SignatureGetTimeMethodInfo
    ResolveSignatureMethod "getTimeZone" o = SignatureGetTimeZoneMethodInfo
    ResolveSignatureMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveSignatureMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveSignatureMethod l o = O.MethodResolutionFailed l o

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

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveSignatureMethod t Signature, O.MethodInfo info Signature p) => O.IsLabel t (Signature -> 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

#endif

-- VVV Prop "encoding"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Nothing,Nothing)

getSignatureEncoding :: (MonadIO m, IsSignature o) => o -> m (Maybe T.Text)
getSignatureEncoding obj = liftIO $ getObjectPropertyString obj "encoding"

constructSignatureEncoding :: (IsSignature o) => T.Text -> IO (GValueConstruct o)
constructSignatureEncoding val = constructObjectPropertyString "encoding" (Just val)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data SignatureEncodingPropertyInfo
instance AttrInfo SignatureEncodingPropertyInfo where
    type AttrAllowedOps SignatureEncodingPropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint SignatureEncodingPropertyInfo = (~) T.Text
    type AttrBaseTypeConstraint SignatureEncodingPropertyInfo = IsSignature
    type AttrGetType SignatureEncodingPropertyInfo = (Maybe T.Text)
    type AttrLabel SignatureEncodingPropertyInfo = "encoding"
    type AttrOrigin SignatureEncodingPropertyInfo = Signature
    attrGet _ = getSignatureEncoding
    attrSet _ = undefined
    attrConstruct _ = constructSignatureEncoding
    attrClear _ = undefined
#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
instance O.HasAttributeList Signature
type instance O.AttributeList Signature = SignatureAttributeList
type SignatureAttributeList = ('[ '("encoding", SignatureEncodingPropertyInfo), '("native", Ggit.Native.NativeNativePropertyInfo)] :: [(Symbol, *)])
#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
signatureEncoding :: AttrLabelProxy "encoding"
signatureEncoding = AttrLabelProxy

#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type instance O.SignalList Signature = SignatureSignalList
type SignatureSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method Signature::new
-- method type : Constructor
-- Args : [Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the name of the person.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "email", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the email of the person.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "signature_time", argType = TInterface (Name {namespace = "GLib", name = "DateTime"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the time when the action happened.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "Signature"}))
-- throws : True
-- Skip return : False

foreign import ccall "ggit_signature_new" ggit_signature_new :: 
    CString ->                              -- name : TBasicType TUTF8
    CString ->                              -- email : TBasicType TUTF8
    Ptr GLib.DateTime.DateTime ->           -- signature_time : TInterface (Name {namespace = "GLib", name = "DateTime"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Signature)

{- |
Creates a new 'GI.Ggit.Objects.Signature.Signature'. Name and e-mail are assumed to be in UTF-8.
-}
signatureNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@name@/: the name of the person. -}
    -> T.Text
    {- ^ /@email@/: the email of the person. -}
    -> GLib.DateTime.DateTime
    {- ^ /@signatureTime@/: the time when the action happened. -}
    -> m Signature
    {- ^ __Returns:__ a newly allocated 'GI.Ggit.Objects.Signature.Signature'. /(Can throw 'Data.GI.Base.GError.GError')/ -}
signatureNew name email signatureTime = liftIO $ do
    name' <- textToCString name
    email' <- textToCString email
    signatureTime' <- unsafeManagedPtrGetPtr signatureTime
    onException (do
        result <- propagateGError $ ggit_signature_new name' email' signatureTime'
        checkUnexpectedReturnNULL "signatureNew" result
        result' <- (wrapObject Signature) result
        touchManagedPtr signatureTime
        freeMem name'
        freeMem email'
        return result'
     ) (do
        freeMem name'
        freeMem email'
     )

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
#endif

-- method Signature::new_now
-- method type : Constructor
-- Args : [Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the name of the person.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "email", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the email of the person.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "Signature"}))
-- throws : True
-- Skip return : False

foreign import ccall "ggit_signature_new_now" ggit_signature_new_now :: 
    CString ->                              -- name : TBasicType TUTF8
    CString ->                              -- email : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Signature)

{- |
Creates a new 'GI.Ggit.Objects.Signature.Signature' with a timestamp of \'now\'. Name and e-mail are
assumed to be in UTF-8.
-}
signatureNewNow ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@name@/: the name of the person. -}
    -> T.Text
    {- ^ /@email@/: the email of the person. -}
    -> m Signature
    {- ^ __Returns:__ a newly allocated 'GI.Ggit.Objects.Signature.Signature'. /(Can throw 'Data.GI.Base.GError.GError')/ -}
signatureNewNow name email = liftIO $ do
    name' <- textToCString name
    email' <- textToCString email
    onException (do
        result <- propagateGError $ ggit_signature_new_now name' email'
        checkUnexpectedReturnNULL "signatureNewNow" result
        result' <- (wrapObject Signature) result
        freeMem name'
        freeMem email'
        return result'
     ) (do
        freeMem name'
        freeMem email'
     )

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
#endif

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

foreign import ccall "ggit_signature_copy" ggit_signature_copy :: 
    Ptr Signature ->                        -- signature : TInterface (Name {namespace = "Ggit", name = "Signature"})
    IO (Ptr Signature)

{- |
Create a copy of the signature.
-}
signatureCopy ::
    (B.CallStack.HasCallStack, MonadIO m, IsSignature a) =>
    a
    {- ^ /@signature@/: a 'GI.Ggit.Objects.Signature.Signature'. -}
    -> m Signature
    {- ^ __Returns:__ a 'GI.Ggit.Objects.Signature.Signature'. -}
signatureCopy signature = liftIO $ do
    signature' <- unsafeManagedPtrCastPtr signature
    result <- ggit_signature_copy signature'
    checkUnexpectedReturnNULL "signatureCopy" result
    result' <- (wrapObject Signature) result
    touchManagedPtr signature
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data SignatureCopyMethodInfo
instance (signature ~ (m Signature), MonadIO m, IsSignature a) => O.MethodInfo SignatureCopyMethodInfo a signature where
    overloadedMethod _ = signatureCopy

#endif

-- method Signature::get_email
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "signature", argType = TInterface (Name {namespace = "Ggit", name = "Signature"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitSignature.", 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 "ggit_signature_get_email" ggit_signature_get_email :: 
    Ptr Signature ->                        -- signature : TInterface (Name {namespace = "Ggit", name = "Signature"})
    IO CString

{- |
Gets the email of the person.
-}
signatureGetEmail ::
    (B.CallStack.HasCallStack, MonadIO m, IsSignature a) =>
    a
    {- ^ /@signature@/: a 'GI.Ggit.Objects.Signature.Signature'. -}
    -> m T.Text
    {- ^ __Returns:__ the email of the person. -}
signatureGetEmail signature = liftIO $ do
    signature' <- unsafeManagedPtrCastPtr signature
    result <- ggit_signature_get_email signature'
    checkUnexpectedReturnNULL "signatureGetEmail" result
    result' <- cstringToText result
    touchManagedPtr signature
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data SignatureGetEmailMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsSignature a) => O.MethodInfo SignatureGetEmailMethodInfo a signature where
    overloadedMethod _ = signatureGetEmail

#endif

-- method Signature::get_name
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "signature", argType = TInterface (Name {namespace = "Ggit", name = "Signature"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitSignature.", 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 "ggit_signature_get_name" ggit_signature_get_name :: 
    Ptr Signature ->                        -- signature : TInterface (Name {namespace = "Ggit", name = "Signature"})
    IO CString

{- |
Gets the name of the person.
-}
signatureGetName ::
    (B.CallStack.HasCallStack, MonadIO m, IsSignature a) =>
    a
    {- ^ /@signature@/: a 'GI.Ggit.Objects.Signature.Signature'. -}
    -> m T.Text
    {- ^ __Returns:__ the name of the person. -}
signatureGetName signature = liftIO $ do
    signature' <- unsafeManagedPtrCastPtr signature
    result <- ggit_signature_get_name signature'
    checkUnexpectedReturnNULL "signatureGetName" result
    result' <- cstringToText result
    touchManagedPtr signature
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data SignatureGetNameMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsSignature a) => O.MethodInfo SignatureGetNameMethodInfo a signature where
    overloadedMethod _ = signatureGetName

#endif

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

foreign import ccall "ggit_signature_get_time" ggit_signature_get_time :: 
    Ptr Signature ->                        -- signature : TInterface (Name {namespace = "Ggit", name = "Signature"})
    IO (Ptr GLib.DateTime.DateTime)

{- |
Gets the time when the action happened. Note that the time is returned in
the timezone of the commit (see @/ggit_signature_get_time_zone/@).
-}
signatureGetTime ::
    (B.CallStack.HasCallStack, MonadIO m, IsSignature a) =>
    a
    {- ^ /@signature@/: a 'GI.Ggit.Objects.Signature.Signature'. -}
    -> m GLib.DateTime.DateTime
    {- ^ __Returns:__ the time when the action happened. -}
signatureGetTime signature = liftIO $ do
    signature' <- unsafeManagedPtrCastPtr signature
    result <- ggit_signature_get_time signature'
    checkUnexpectedReturnNULL "signatureGetTime" result
    result' <- (wrapBoxed GLib.DateTime.DateTime) result
    touchManagedPtr signature
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data SignatureGetTimeMethodInfo
instance (signature ~ (m GLib.DateTime.DateTime), MonadIO m, IsSignature a) => O.MethodInfo SignatureGetTimeMethodInfo a signature where
    overloadedMethod _ = signatureGetTime

#endif

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

foreign import ccall "ggit_signature_get_time_zone" ggit_signature_get_time_zone :: 
    Ptr Signature ->                        -- signature : TInterface (Name {namespace = "Ggit", name = "Signature"})
    IO (Ptr GLib.TimeZone.TimeZone)

{- |
Gets the timezone in which the action happened.
-}
signatureGetTimeZone ::
    (B.CallStack.HasCallStack, MonadIO m, IsSignature a) =>
    a
    {- ^ /@signature@/: a 'GI.Ggit.Objects.Signature.Signature'. -}
    -> m GLib.TimeZone.TimeZone
    {- ^ __Returns:__ the timezone in which the action happened. -}
signatureGetTimeZone signature = liftIO $ do
    signature' <- unsafeManagedPtrCastPtr signature
    result <- ggit_signature_get_time_zone signature'
    checkUnexpectedReturnNULL "signatureGetTimeZone" result
    result' <- (wrapBoxed GLib.TimeZone.TimeZone) result
    touchManagedPtr signature
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data SignatureGetTimeZoneMethodInfo
instance (signature ~ (m GLib.TimeZone.TimeZone), MonadIO m, IsSignature a) => O.MethodInfo SignatureGetTimeZoneMethodInfo a signature where
    overloadedMethod _ = signatureGetTimeZone

#endif