from django.db import models
from django.contrib.auth.models import User


class Consumption(models.Model):
    DRINK_CHOICES = [
        ('coffee', 'Coffee'),
        ('tea', 'Tea'),
        ('decaf', 'Decaf'),
        ('energy', 'Energy Drink'),
    ]
    SIZE_CHOICES = [
        ('small', 'Small (240ml)'),
        ('medium', 'Medium (350ml)'),
        ('large', 'Large (470ml)'),
    ]

    user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
    drink_type = models.CharField(max_length=10, choices=DRINK_CHOICES, default='coffee')
    size = models.CharField(max_length=10, choices=SIZE_CHOICES, default='medium')
    timestamp = models.DateTimeField(auto_now_add=True)
    session_key = models.CharField(max_length=40, db_index=True, null=True, blank=True)

    def __str__(self):
        return f"{self.get_drink_type_display()} ({self.get_size_display()}) at {self.timestamp}"
