"""$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/dulcinea/lib/interaction.py $
$Id: interaction.py 25735 2004-12-09 18:45:05Z rmasse $
"""

from types import FunctionType
from dulcinea.history import History
from dulcinea.spec import require, any

class Interactable:

    """Storage for a set of interaction events on an object of interest

    Instance attributes:
      interactions : History
        the interaction history with this interactible object
      decorator : FunctionType
    """

    interactions_is = History
    decorator_is = any(None, FunctionType)

    EMAIL = 'email'
    MAIL = 'mail'
    PHONE = 'phone'
    FAX = 'fax'

    INTERACTION_CODES = (EMAIL, MAIL, PHONE, FAX)

    def __init__(self):
        self.interactions = History()
        self.decorator = None

    def set_decorator(self, decorator):
        require(decorator, FunctionType)
        if self.decorator is not decorator:
            self.decorator = decorator

    def get_decorator(self):
        return self.decorator

    def with_decorator(self, decorator):
        self.set_decorator(decorator)
        return self

    def get_interaction_history(self):
        return self.interactions

    def get_interaction_codes(self):
        return self.INTERACTION_CODES

    def record_interaction(self, user, code, comment):
        self.interactions.add_event(user, code, comment)


