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


class Offer(models.Model):
    OFFER_TYPE_CHOICES = (
        ('vpn', 'VPN'),
        ('dsl', 'DSL'),
        ('other', 'Other'),
    )
    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 €')
    type = models.CharField(max_length=50, choices=OFFER_TYPE_CHOICES)
    
    def __unicode__(self):
        return u'%s - %d€ / %im [%s]' % (self.name, self.period_fees,
                                          self.billing_period, self.type)

    class Meta:
        verbose_name = 'offre'


class OfferSubscription(models.Model):
    """Only contains administrative details about a subscription, not
    technical.  Nothing here should end up into the LDAP backend."""
    subscription_date = models.DateField(
        null=False,
        blank=False,
        default=datetime.date.today,
        verbose_name='Date de souscription à l\'offre')
    # TODO: for data retention, prevent deletion of a subscription object
    # while the resign date is recent enough (e.g. one year in France).
    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'
