# -*- coding: utf-8 -*-
import datetime
from django.db import models


class Service(models.Model):
    name = models.CharField(max_length=255, blank=False, null=False,
                            verbose_name='Nom du service')
    
    def __unicode__(self):
        return self.name


class Offer(models.Model):
    name = models.CharField(max_length=255, blank=False, null=False,
                            verbose_name='Nom de l\'offre')
    billing_period = models.IntegerField(blank=False, null=False, default=1,
                                         verbose_name='Période de facturation',
                                         help_text='en mois')
    period_fees = models.DecimalField(max_digits=5, decimal_places=2,
                                      blank=False, null=False,
                                      verbose_name='Montant par période de '
                                                   'facturation',
                                      help_text='en €')
    initial_fees = models.DecimalField(max_digits=5, decimal_places=2,
                                      blank=False, null=False,
                                      verbose_name='Frais de mise en service',
                                      help_text='en €')
    service = models.ForeignKey('Service')
    
    def __unicode__(self):
        return u'%s - %d€ / %im [%s]' % (self.name, self.period_fees,
                                          self.billing_period, self.service)

    class Meta:
        verbose_name = 'offre'


class OfferSubscription(models.Model):
    subscription_date = models.DateField(
        null=False,
        blank=False,
        default=datetime.date.today,
        verbose_name='Date de souscription à l\'offre')
    resign_date = models.DateField(
        null=True,
        blank=True,
        verbose_name='Date de résiliation')
    commitment = models.IntegerField(blank=False, null=False,
                                     verbose_name='Période d\'engagement',
                                     help_text = 'en mois',
                                     default=0)
    member = models.ForeignKey('members.Member', verbose_name='Membre')
    offer = models.ForeignKey('Offer', verbose_name='Offre')

    def __unicode__(self):
        return u'%s - %s - %s' % (self.member, self.offer.name,
                                   self.subscription_date)

    class Meta:
        verbose_name = 'abonnement'
