from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext, ugettext_lazy as _

from django_facebook.models import FacebookProfileModel

from geoposition.fields import GeopositionField

class Member(FacebookProfileModel):
    user = models.OneToOneField(User)

from django.db.models.signals import post_save
from django.dispatch import receiver

@receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs):
    if created: 
        profile, new = Member.objects.get_or_create(user=instance)

class Team(models.Model):
    member = models.ForeignKey(Member)
    name = models.CharField(_('Team Name'), max_length=100)
    description = models.TextField(_('Description'))
    location = models.TextField(_('Location'))
    position = GeopositionField(_('Position'))
    appointed_time = models.DateTimeField(_("Appointed time"))
    min_member = models.IntegerField(_("Minimum member"))
    max_member = models.IntegerField(_("Maximum member"))
    succeed = models.BooleanField(_("Succeed"))

EVALUATION_CHOICES = (
    (-20, 'Very bad'),
    (-10, 'Bad'),
    (0, 'Normal'),
    (10, 'Good'),
    (20, 'Very good'),
)

class TeamLog(models.Model):
    member = models.ForeignKey(Member)
    team = models.ForeignKey(Team)
    evaluation = models.IntegerField(_("Evaluation"), choices=EVALUATION_CHOICES, default=0)
    impeached = models.BooleanField(_("Impeached"), default=False)
