from django.db import models

class Recipe(models.Model):
    title = models.CharField(max_length=255)
    slug = models.SlugField()
    description = models.TextField(blank=True)
    tokri_ingredients = models.ManyToManyField("TokriVegetable", through='RecipeTokri')
    preparation = models.TextField(blank=True)
    serves = models.IntegerField(null=True, help_text="Serves approximately how many people?", blank=True)
    preparation_time = models.IntegerField(null=True, help_text="Approximate time to make, in minutes", blank=True)
    
    
    def __unicode__(self):
        return self.title


class TokriVegetable(models.Model):
    name = models.CharField(max_length=255)
    types = models.ManyToManyField("VegetableType", blank=True)
    slug = models.SlugField()
    description = models.TextField(blank=True)
    main_image = models.ImageField(upload_to='veggie_main_images', null=True)    
    season = models.ForeignKey("Season", null=True)

    def __unicode__(self):
        return self.name

class VegetableType(models.Model):
    name = models.CharField(max_length=255)
    description = models.TextField(blank=True)

    def __unicode__(self):
        return self.name


class VegetableLink(models.Model):
    url = models.URLField()
    caption = models.CharField(max_length=512, blank=True)
    vegetable = models.ForeignKey(TokriVegetable)

    def __unicode__(self):
        return self.url

MONTH_CHOICES = (
    ('Jan', 'January'),
    ('Feb', 'February'),
    ('Mar', 'March'),
    ('Apr', 'April'),
    ('May', 'May'),
    ('Jun', 'June'),
    ('Jul', 'July'),
    ('Aug', 'August'),
    ('Sep', 'September'),
    ('Oct', 'October'),
    ('Nov', 'November'),
    ('Dec', 'December'),
)

class Season(models.Model):
    name = models.CharField(max_length=255)
    start_month = models.CharField(max_length=5, choices=MONTH_CHOICES)
    end_month = models.CharField(max_length=5, choices=MONTH_CHOICES)
    
    def __unicode__(self):
        return self.name

class RecipeTokri(models.Model):
    recipe = models.ForeignKey(Recipe)
    tokri_ingredient = models.ForeignKey(TokriVegetable)
    amount = models.CharField(max_length=255, blank=True)


class AlternativeName(models.Model):
    ingredient = models.ForeignKey(TokriVegetable)
    name_roman = models.CharField(max_length=255)
    name_unicode = models.CharField(max_length=255)
    language = models.ForeignKey("Language", null=True)

    def __unicode__(self):
        return self.name_roman


class Language(models.Model):
    name = models.CharField(max_length=255)    
    lang_code = models.CharField(max_length=4)
    
    def __unicode__(self):
        return self.name


class OtherIngredient(models.Model):
    name = models.CharField(max_length=255)
    amount = models.CharField(max_length=255)
    recipe = models.ForeignKey(Recipe)

    def __unicode__(self):
        return self.name

class TokriImage(models.Model):
    ingredient = models.ForeignKey(TokriVegetable)
    image = models.ImageField(upload_to='veggie_images')
    caption = models.CharField(max_length=512, blank=True)

    def __unicode__(self):
        return self.caption
# Create your models here.
