# Path: app/timetables/models.py
# class Course(SlugifyMixin, models.Model):
#     """
#     Model representing the sequence/order of different kind
#     of dishes for a meal."""
# 
#     name = models.CharField(
#         max_length=150,
#         verbose_name='Course Name',
#         help_text='Example: appetizer, main course, dessert'
#     )
#     slug = models.SlugField(
#         max_length=150, unique=True, null=True, editable=False
#     )
#     sequence_order = models.PositiveSmallIntegerField(
#         unique=True,
#         help_text=(
#             'The numerical order of the dishes for a meal option. '
#             'E.g, 1 for appetizer, 2 for main course'
#         )
#     )
# 
#     slugify_field = 'name'
# 
#     def __str__(self):
#         return self.name
# 
# class MenuItem(TimestampMixin):
#     """
#     Model representing a Menu Item.
# 
#     A MenuItem represents the particular meal combination that is to be
#     served on a given cycle-day of a particular timetable.
#     """
# 
#     timetable = models.ForeignKey(Timetable, on_delete=models.CASCADE)
#     cycle_day = models.PositiveSmallIntegerField(
#         validators=[MinValueValidator(1)]
#     )
#     meal = models.ForeignKey(Meal, on_delete=models.CASCADE)
#     course = models.ForeignKey(Course, on_delete=models.CASCADE)
#     dish = models.ForeignKey(Dish, on_delete=models.CASCADE)
# 
#     def clean(self):
#         if self.cycle_day and self.timetable.cycle_length:
#             if self.cycle_day > self.timetable.cycle_length:
#                 raise ValidationError(
#                     _('Supply a cycle day in the range 1 - {}'.format(self.timetable.cycle_length))
#                 )
#         super().clean()
# 
#     def save(self, *args, **kwargs):
#         # Calling full_clean instead of clean to ensure validators are called
#         self.full_clean()
#         return super().save(*args, **kwargs)
# 
#     def __str__(self):
#         return '{} ({}) for {} on cycle {} timetable {}'.format(
#             self.dish, self.course, self.meal, self.cycle_day, self.timetable
#         )
# 
#     class Meta:
#         unique_together = ('timetable', 'cycle_day', 'meal', 'course', 'dish')
#         verbose_name = 'Menu Item'
#         verbose_name_plural = 'Menu Items'
# 
# 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')


import graphene
from graphene_django import DjangoObjectType
from graphene_django.converter import convert_django_field
from hashid_field import HashidField
from app.timetables.models import Course, MenuItem, Serving



@convert_django_field.register(HashidField)
def hashidfield_convert(field, registry=None):
    return graphene.String()


class ServingNode(DjangoObjectType):
    original_id = graphene.Int()

    class Meta:
        model = Serving
        interfaces = (graphene.relay.Node, )

    def resolve_original_id(self, args, context, info):
        return self.id


class MenuItemNode(DjangoObjectType):
    original_id = graphene.Int()

    class Meta:

# Path: app/timetables/models.py
# class Course(SlugifyMixin, models.Model):
#     """
#     Model representing the sequence/order of different kind
#     of dishes for a meal."""
# 
#     name = models.CharField(
#         max_length=150,
#         verbose_name='Course Name',
#         help_text='Example: appetizer, main course, dessert'
#     )
#     slug = models.SlugField(
#         max_length=150, unique=True, null=True, editable=False
#     )
#     sequence_order = models.PositiveSmallIntegerField(
#         unique=True,
#         help_text=(
#             'The numerical order of the dishes for a meal option. '
#             'E.g, 1 for appetizer, 2 for main course'
#         )
#     )
# 
#     slugify_field = 'name'
# 
#     def __str__(self):
#         return self.name
# 
# class MenuItem(TimestampMixin):
#     """
#     Model representing a Menu Item.
# 
#     A MenuItem represents the particular meal combination that is to be
#     served on a given cycle-day of a particular timetable.
#     """
# 
#     timetable = models.ForeignKey(Timetable, on_delete=models.CASCADE)
#     cycle_day = models.PositiveSmallIntegerField(
#         validators=[MinValueValidator(1)]
#     )
#     meal = models.ForeignKey(Meal, on_delete=models.CASCADE)
#     course = models.ForeignKey(Course, on_delete=models.CASCADE)
#     dish = models.ForeignKey(Dish, on_delete=models.CASCADE)
# 
#     def clean(self):
#         if self.cycle_day and self.timetable.cycle_length:
#             if self.cycle_day > self.timetable.cycle_length:
#                 raise ValidationError(
#                     _('Supply a cycle day in the range 1 - {}'.format(self.timetable.cycle_length))
#                 )
#         super().clean()
# 
#     def save(self, *args, **kwargs):
#         # Calling full_clean instead of clean to ensure validators are called
#         self.full_clean()
#         return super().save(*args, **kwargs)
# 
#     def __str__(self):
#         return '{} ({}) for {} on cycle {} timetable {}'.format(
#             self.dish, self.course, self.meal, self.cycle_day, self.timetable
#         )
# 
#     class Meta:
#         unique_together = ('timetable', 'cycle_day', 'meal', 'course', 'dish')
#         verbose_name = 'Menu Item'
#         verbose_name_plural = 'Menu Items'
# 
# 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/api/cruds/serving_crud.py
import graphene
from graphene_django import DjangoObjectType
from graphene_django.converter import convert_django_field
from hashid_field import HashidField
from app.timetables.models import Course, MenuItem, Serving




@convert_django_field.register(HashidField)
def hashidfield_convert(field, registry=None):
    return graphene.String()


class ServingNode(DjangoObjectType):
    original_id = graphene.Int()

    class Meta:
        model = Serving
        interfaces = (graphene.relay.Node, )

    def resolve_original_id(self, args, context, info):
        return self.id


class MenuItemNode(DjangoObjectType):
    original_id = graphene.Int()

    class Meta:

        model = MenuItem