# Path: common/mixins.py
# class TimestampMixin(models.Model):
#     """Mixin for date and timestamp. Inherits django's models.Model."""
# 
#     date_created = models.DateTimeField(auto_now_add=True)
#     date_modified = models.DateTimeField(auto_now=True)
# 
#     class Meta:
#         abstract = True
# 
# Path: app/timetables/models.py
# class Serving(TimestampMixin):
#     """Model representing already served menu."""
# 
#     public_id = HashidField(
#         alphabet='0123456789abcdefghijklmnopqrstuvwxyz',
#         default=timestamp_seconds,
#         unique=True
#     )
#     menu_item = models.ForeignKey(MenuItem, on_delete=models.CASCADE)
#     vendor = models.ForeignKey(Vendor, on_delete=models.CASCADE)
#     date_served = models.DateField()
# 
#     def __str__(self):
#         return '{} served on {}'.format(self.menu_item, self.date_served)
# 
#     class Meta:
#         unique_together = ('menu_item', 'vendor', 'date_served')


from django.db import models
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from common.mixins import TimestampMixin
from app.timetables.models import Serving
from __future__ import unicode_literals




class Review(TimestampMixin):
    """Model representing ratings and comments on served menu items."""

    EXCELLENT = 5
    GOOD = 4
    FAIR = 3
    POOR = 2
    TERRIBLE = 1

    RATINGS = (
        (EXCELLENT, 'EXCELLENT'),
        (GOOD, 'GOOD'),
        (FAIR, 'FAIR'),
        (POOR, 'POOR'),
        (TERRIBLE, 'TERRIBLE')
    )

    # Make nullable for anonymity of reviewers.
    user = models.ForeignKey(
        User, on_delete=models.SET_NULL, blank=True, null=True
    )
    # anonymity_id is just a hashed unique identifier for the reviewer used
    # as a check prevent multiple reviews from one person
    anonymity_id = models.CharField(blank=True, null=True, max_length=250)

# Path: common/mixins.py
# class TimestampMixin(models.Model):
#     """Mixin for date and timestamp. Inherits django's models.Model."""
# 
#     date_created = models.DateTimeField(auto_now_add=True)
#     date_modified = models.DateTimeField(auto_now=True)
# 
#     class Meta:
#         abstract = True
# 
# Path: app/timetables/models.py
# class Serving(TimestampMixin):
#     """Model representing already served menu."""
# 
#     public_id = HashidField(
#         alphabet='0123456789abcdefghijklmnopqrstuvwxyz',
#         default=timestamp_seconds,
#         unique=True
#     )
#     menu_item = models.ForeignKey(MenuItem, on_delete=models.CASCADE)
#     vendor = models.ForeignKey(Vendor, on_delete=models.CASCADE)
#     date_served = models.DateField()
# 
#     def __str__(self):
#         return '{} served on {}'.format(self.menu_item, self.date_served)
# 
#     class Meta:
#         unique_together = ('menu_item', 'vendor', 'date_served')


# Path: app/reviews/models.py
from django.db import models
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from common.mixins import TimestampMixin
from app.timetables.models import Serving

from __future__ import unicode_literals




class Review(TimestampMixin):
    """Model representing ratings and comments on served menu items."""

    EXCELLENT = 5
    GOOD = 4
    FAIR = 3
    POOR = 2
    TERRIBLE = 1

    RATINGS = (
        (EXCELLENT, 'EXCELLENT'),
        (GOOD, 'GOOD'),
        (FAIR, 'FAIR'),
        (POOR, 'POOR'),
        (TERRIBLE, 'TERRIBLE')
    )

    # Make nullable for anonymity of reviewers.
    user = models.ForeignKey(
        User, on_delete=models.SET_NULL, blank=True, null=True
    )
    # anonymity_id is just a hashed unique identifier for the reviewer used
    # as a check prevent multiple reviews from one person
    anonymity_id = models.CharField(blank=True, null=True, max_length=250)

    serving = models.ForeignKey(Serving, on_delete=models.CASCADE)