# Path: app/timetables/models.py
# class Event(TimestampMixin):
#     """
#     Model representing event.
# 
#     Event represent a date or range of dates to which a
#     specific timetable will be active or functional.
#     """
# 
#     NO_MEAL = 'no-meal'
# 
#     ACTION_CHOICES = (
#         (NO_MEAL, 'no meal will be served'),
#     )
# 
#     name = models.CharField(max_length=150)
#     timetable = models.ForeignKey(Timetable, on_delete=models.CASCADE)
#     action = models.CharField(max_length=255, choices=ACTION_CHOICES)
#     start_date = models.DateTimeField()
#     end_date = models.DateTimeField()
# 
#     def clean(self):
#         if self.start_date and self.end_date:
#             if self.start_date >= self.end_date:
#                 raise ValidationError(_('Start date must be less than end date.'))
#         super().clean()
# 
#     def save(self, *args, **kwargs):
#         self.clean()
#         return super().save(*args, **kwargs)
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         unique_together = ('name', 'start_date', 'end_date')
# 
# Path: app/api/cruds/timetable_crud.py
# class TimetableNode(DjangoObjectType):
#     original_id = graphene.Int()
#     vendors = DjangoConnectionField(lambda: VendorNode)
#     admins = DjangoConnectionField(lambda: UserNode)
# 
#     class Meta:
#         model = Timetable
#         interfaces = (graphene.relay.Node, )
# 
#     def resolve_original_id(self, args, context, info):
#         return self.id


import graphene
from graphene_django import DjangoConnectionField, DjangoObjectType
from django_filters import OrderingFilter, FilterSet
from app.timetables.models import Event
from .timetable_crud import TimetableNode



class EventFilter(FilterSet):
    order_by = OrderingFilter(fields=[('name', 'name'),
                                      ('timetable', 'timetable'),
                                      ('action', 'action'),
                                      ('start_date', 'start_date'),
                                      ('end_date', 'end_date')])

    class Meta:
        fields = {
            'name': ['icontains']
        }
        model = Event


class EventNode(DjangoObjectType):
    original_id = graphene.Int()
    timetable = DjangoConnectionField(lambda: TimetableNode)

    class Meta:

# Path: app/timetables/models.py
# class Event(TimestampMixin):
#     """
#     Model representing event.
# 
#     Event represent a date or range of dates to which a
#     specific timetable will be active or functional.
#     """
# 
#     NO_MEAL = 'no-meal'
# 
#     ACTION_CHOICES = (
#         (NO_MEAL, 'no meal will be served'),
#     )
# 
#     name = models.CharField(max_length=150)
#     timetable = models.ForeignKey(Timetable, on_delete=models.CASCADE)
#     action = models.CharField(max_length=255, choices=ACTION_CHOICES)
#     start_date = models.DateTimeField()
#     end_date = models.DateTimeField()
# 
#     def clean(self):
#         if self.start_date and self.end_date:
#             if self.start_date >= self.end_date:
#                 raise ValidationError(_('Start date must be less than end date.'))
#         super().clean()
# 
#     def save(self, *args, **kwargs):
#         self.clean()
#         return super().save(*args, **kwargs)
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         unique_together = ('name', 'start_date', 'end_date')
# 
# Path: app/api/cruds/timetable_crud.py
# class TimetableNode(DjangoObjectType):
#     original_id = graphene.Int()
#     vendors = DjangoConnectionField(lambda: VendorNode)
#     admins = DjangoConnectionField(lambda: UserNode)
# 
#     class Meta:
#         model = Timetable
#         interfaces = (graphene.relay.Node, )
# 
#     def resolve_original_id(self, args, context, info):
#         return self.id


# Path: app/api/cruds/event_crud.py
import graphene
from graphene_django import DjangoConnectionField, DjangoObjectType
from django_filters import OrderingFilter, FilterSet
from app.timetables.models import Event
from .timetable_crud import TimetableNode




class EventFilter(FilterSet):
    order_by = OrderingFilter(fields=[('name', 'name'),
                                      ('timetable', 'timetable'),
                                      ('action', 'action'),
                                      ('start_date', 'start_date'),
                                      ('end_date', 'end_date')])

    class Meta:
        fields = {
            'name': ['icontains']
        }
        model = Event


class EventNode(DjangoObjectType):
    original_id = graphene.Int()
    timetable = DjangoConnectionField(lambda: TimetableNode)

    class Meta:

        model = Event