# Path: sendinel/backend/texthelper.py
# def date_to_text(weekday, day, month, hour, minutes):
# def generate_text(contents, template, is_sms = True):
# def get_content_length(contents):
# def replace_dollar_signs(contents):
# def reduce_contents(contents, chars_left):
# 
# Path: sendinel/backend/models.py
# class Patient(User):
#     """
#     Represent a patient.
#     """
#     
#     phone_number = models.CharField(max_length = 20)
#     
#     def __unicode__(self):
#         return "Patient <%s>" % self.phone_number
# 
# class Sendable(models.Model):
#     """
#     Define an interface for a Sendable object.
#     """
# 
#     class Meta:
#         abstract = True
#         
#     way_of_communication = models.ForeignKey(WayOfCommunication)
# 
#     recipient = models.ForeignKey(Patient)
#     
#     def __unicode__(self):
#         return "%s %s" % (unicode(self.recipient), self.way_of_communication.verbose_name)
#     
#     def get_data_for_sending(self):
#         """
#         Prepare OutputData for selected way_of_communication.
#         Return an object of a subclass of OutputData.
#         """
#         
#         call = "self.get_data_for_%s()" % self.way_of_communication.name      
#         logger.info("sendable.get_data_for_sending() calling method: " + call)        
#         return eval(call)
#         
#     def create_scheduled_event(self, send_time):
#         """
#         Create a scheduled event for a specific send_time
#         @param send_time: Datetime object with the time of the reminder 
#         """        
#         scheduled_event = ScheduledEvent(sendable = self,
#                                          send_time = send_time)
#         scheduled_event.save()
# 
# class WayOfCommunication(models.Model):
#     """
#     Represent a possible Way of Communication like SMS
#     """
#     
#     name = models.CharField(max_length = 255, blank = False, null = False)
#     verbose_name = models.CharField(max_length = 255)
#     enabled = models.BooleanField()
#     can_send_immediately = models.BooleanField()
#     
#     def __unicode__(self):
#         return self.verbose_name
# 
# Path: sendinel/backend/output.py
# class SMSOutputData(OutputData):
#     """
#     Define necessary OutputData for sending via sms.
#     """
#     
#     phone_number = None
#     
#     def send(self):
#         logger.info("Sending via SMS")
#         vc = voicecall.Voicecall()
#         return vc.conduct_sms(self.phone_number, self.data, "outbound-sms")
# 
# class VoiceOutputData(OutputData):
#     """
#     Define necessary OutputData for sending via voice.
#     """
#     
#     phone_number = None
#     
#     def send(self):
#         logger.info("Sending via Phone Call")
#         call = voicecall.Voicecall()
#         return call.conduct_call(self.phone_number, self.data, "outbound-call")


from string import Template
from django.db import models
from django.utils.translation import ugettext_lazy
from sendinel.backend import texthelper
from sendinel.backend.models import Patient, \
                                    Sendable, \
                                    WayOfCommunication
from sendinel.backend.output import SMSOutputData, \
                                    VoiceOutputData
        Generate the message for an InfoMessage.
        Return SMSOutputData for sending.
        """
        
        data = SMSOutputData()           
        data.data = texthelper.generate_text({'text': self.text},
                                             InfoMessage.template)
        data.phone_number = self.recipient.phone_number
                
        return data
        
    def get_data_for_voice(self):
        """
        Prepare OutputData for voicecall.
        Generate the message for an InfoMessage.
        Return VoiceOutputData for sending.
        """
        
        data = VoiceOutputData()
        data.data = self.text
        data.phone_number = self.recipient.phone_number
            
        return data


class Subscription(models.Model):
    """
    Represents a patient's subscription to an infoservice
    """


# Path: sendinel/backend/texthelper.py
# def date_to_text(weekday, day, month, hour, minutes):
# def generate_text(contents, template, is_sms = True):
# def get_content_length(contents):
# def replace_dollar_signs(contents):
# def reduce_contents(contents, chars_left):
# 
# Path: sendinel/backend/models.py
# class Patient(User):
#     """
#     Represent a patient.
#     """
#     
#     phone_number = models.CharField(max_length = 20)
#     
#     def __unicode__(self):
#         return "Patient <%s>" % self.phone_number
# 
# class Sendable(models.Model):
#     """
#     Define an interface for a Sendable object.
#     """
# 
#     class Meta:
#         abstract = True
#         
#     way_of_communication = models.ForeignKey(WayOfCommunication)
# 
#     recipient = models.ForeignKey(Patient)
#     
#     def __unicode__(self):
#         return "%s %s" % (unicode(self.recipient), self.way_of_communication.verbose_name)
#     
#     def get_data_for_sending(self):
#         """
#         Prepare OutputData for selected way_of_communication.
#         Return an object of a subclass of OutputData.
#         """
#         
#         call = "self.get_data_for_%s()" % self.way_of_communication.name      
#         logger.info("sendable.get_data_for_sending() calling method: " + call)        
#         return eval(call)
#         
#     def create_scheduled_event(self, send_time):
#         """
#         Create a scheduled event for a specific send_time
#         @param send_time: Datetime object with the time of the reminder 
#         """        
#         scheduled_event = ScheduledEvent(sendable = self,
#                                          send_time = send_time)
#         scheduled_event.save()
# 
# class WayOfCommunication(models.Model):
#     """
#     Represent a possible Way of Communication like SMS
#     """
#     
#     name = models.CharField(max_length = 255, blank = False, null = False)
#     verbose_name = models.CharField(max_length = 255)
#     enabled = models.BooleanField()
#     can_send_immediately = models.BooleanField()
#     
#     def __unicode__(self):
#         return self.verbose_name
# 
# Path: sendinel/backend/output.py
# class SMSOutputData(OutputData):
#     """
#     Define necessary OutputData for sending via sms.
#     """
#     
#     phone_number = None
#     
#     def send(self):
#         logger.info("Sending via SMS")
#         vc = voicecall.Voicecall()
#         return vc.conduct_sms(self.phone_number, self.data, "outbound-sms")
# 
# class VoiceOutputData(OutputData):
#     """
#     Define necessary OutputData for sending via voice.
#     """
#     
#     phone_number = None
#     
#     def send(self):
#         logger.info("Sending via Phone Call")
#         call = voicecall.Voicecall()
#         return call.conduct_call(self.phone_number, self.data, "outbound-call")


# Path: sendinel/infoservices/models.py
from string import Template
from django.db import models
from django.utils.translation import ugettext_lazy
from sendinel.backend import texthelper
from sendinel.backend.models import Patient, \
                                    Sendable, \
                                    WayOfCommunication
from sendinel.backend.output import SMSOutputData, \
                                    VoiceOutputData

        Generate the message for an InfoMessage.
        Return SMSOutputData for sending.
        """
        
        data = SMSOutputData()           
        data.data = texthelper.generate_text({'text': self.text},
                                             InfoMessage.template)
        data.phone_number = self.recipient.phone_number
                
        return data
        
    def get_data_for_voice(self):
        """
        Prepare OutputData for voicecall.
        Generate the message for an InfoMessage.
        Return VoiceOutputData for sending.
        """
        
        data = VoiceOutputData()
        data.data = self.text
        data.phone_number = self.recipient.phone_number
            
        return data


class Subscription(models.Model):
    """
    Represents a patient's subscription to an infoservice
    """


    patient = models.ForeignKey(Patient)