"""
$Id: __init__.py,v 1.2 2005/02/26 17:56:10 sidnei Exp $
"""

from zope.event import notify
from zope.interface import Interface, Attribute
from zope.interface import implements

class IReferenceEvent(Interface):

    sourceUID = Attribute('Reference source (referrer)')
    targetUID = Attribute('Reference target (referred)')
    relationship = Attribute('Relationship')
    reference = Attribute('Reference')

class IReferenceAddedEvent(IReferenceEvent):
    """Reference was added
    """

class IReferenceRemovedEvent(IReferenceEvent):
    """Reference was removed
    """

class ReferenceEvent(object):

    implements(IReferenceEvent)

    def __init__(self, sid, tid, rel, ref):
        self.sourceUID = sid
        self.targetUID = tid
        self.relationship = rel
        self.reference = ref

class ReferenceAddedEvent(ReferenceEvent):
    implements(IReferenceAddedEvent)

class ReferenceRemovedEvent(ReferenceEvent):
    implements(IReferenceRemovedEvent)

def referenceAdded(refObj):
    notify(ReferenceAddedEvent(refObj.sourceUID,
                               refObj.targetUID,
                               refObj.relationship,
                               refObj))

def referenceRemoved(refObj):
    notify(ReferenceRemovedEvent(refObj.sourceUID,
                                 refObj.targetUID,
                                 refObj.relationship,
                                 refObj))
