from django.db import models
from django.urls import reverse
# Create your models here.

class Quantitá(models.Model):
    quantity = models.CharField(max_length=120)
    
    def __str__(self):
        return self.quantity

    class Meta:
        verbose_name = "Quantitá"
        verbose_name_plural = "Quantitá"


class Ingredienti(models.Model):
    ingrediente = models.CharField(max_length=100)
    quantitá_ingrediente = models.ForeignKey(Quantitá,on_delete=models.CASCADE)


    def __repr__(self):
        return self.quantitá_ingrediente.quantity + " " +  self.ingrediente 

    def __str__(self):
        return f"{self.ingrediente}"

    class Meta:
        verbose_name = "Ingrediente"
        verbose_name_plural = "Ingredienti"

class Cocktail(models.Model):
    ingredienti = models.ManyToManyField(Ingredienti)
    nome_cocktail = models.CharField(max_length=120)
    preparazione = models.TextField()
    storia = models.TextField()
    curiositá = models.TextField()
    immagine_cocktail = models.ImageField(upload_to="cocktail_img",blank=True,null=True)

    def __str__(self):
        return f"{self.nome_cocktail}"

    def lista_ingredienti(self):
        return "\n ,".join([i.ingrediente for i in self.ingredienti.all()]) # 

    def get_absolute_url(self):
        return reverse('cocktail', kwargs={'nome_cocktail': self.nome_cocktail}) # ritorno l'absolute url dei cocktail passando come kwargs il nome_cocktail

    class Meta:
        verbose_name = "Cocktail"
        verbose_name_plural = "Cocktails"


class Strumenti(models.Model):
    nome_strumento = models.CharField(max_length=100)
    descrizione = models.CharField(max_length=240)
    immagine_strumenti = models.ImageField(upload_to="strumento",blank=True,null=True)


    def __str__(self):
        return self.nome_strumento

    class Meta:
        verbose_name = "Strumento per Cocktails"
        verbose_name_plural = "Strumenti per Cocktails"


class Bicchieri(models.Model):
    nome_bicchiere = models.CharField(max_length=100)
    descrizione = models.CharField(max_length=240)
    immagine_bicchieri = models.ImageField(upload_to="bicchiere",blank=True,null=True)


    def __str__(self):
        return self.nome_bicchiere

    class Meta:
        verbose_name = "Bicchiere per Cocktails"
        verbose_name_plural = "Bicchieri per Cocktails"
