import datetime

from django.utils import timezone

from django.contrib.auth.models import User
from hknweb.events.models import Event, EventType, Rsvp


class ModelFactory:
    @staticmethod
    def create_user(**kwargs):
        default_kwargs = {
            "username": "default username",
        }
        kwargs = {**default_kwargs, **kwargs}
        return User.objects.create(**kwargs)

    @staticmethod
    def create_event_type(**kwargs):
        default_kwargs = {
            "type": "default event type",
        }
        kwargs = {**default_kwargs, **kwargs}
        return EventType.objects.create(**kwargs)

    @staticmethod
    def create_event(name, event_type, created_by, **kwargs):
        required_kwargs = {
            "name": name,
            "event_type": event_type,
            "created_by": created_by,
        }
        default_kwargs = {
            "start_time": timezone.now(),
            "end_time": timezone.now() + datetime.timedelta(hours=2),
            "location": "default location",
            "description": "default description",
        }
        kwargs = {**required_kwargs, **default_kwargs, **kwargs}
        return Event.objects.create(**kwargs)

    @staticmethod
    def create_rsvp(user, event, **kwargs):
        required_kwargs = {
            "user": user,
            "event": event,
        }
        kwargs = {**required_kwargs, **kwargs}
        return Rsvp.objects.create(**kwargs)

    @staticmethod
    def create_event_with_rsvps():
        event_create_user = ModelFactory.create_user(username="event create user")
        num_rsvps = 3
        rsvp_users = [
            ModelFactory.create_user(username="rsvp_user_{}".format(str(i)))
            for i in range(1, 1 + num_rsvps)
        ]

        event_type = ModelFactory.create_event_type()
        event_name = "custom event name"

        event = ModelFactory.create_event(
            name=event_name,
            event_type=event_type,
            created_by=event_create_user,
            rsvp_limit=num_rsvps - 1,
        )

        rsvps = [ModelFactory.create_rsvp(rsvp_user, event) for rsvp_user in rsvp_users]

        return (
            event_create_user,
            rsvp_users,
            event_type,
            event_name,
            event,
            rsvps,
        )

[((365, 394), 'django.contrib.auth.models.User.objects.create', 'User.objects.create', ([], {}), '(**kwargs)\n', (384, 394), False, 'from django.contrib.auth.models import User\n'), ((591, 625), 'hknweb.events.models.EventType.objects.create', 'EventType.objects.create', ([], {}), '(**kwargs)\n', (615, 625), False, 'from hknweb.events.models import Event, EventType, Rsvp\n'), ((1170, 1200), 'hknweb.events.models.Event.objects.create', 'Event.objects.create', ([], {}), '(**kwargs)\n', (1190, 1200), False, 'from hknweb.events.models import Event, EventType, Rsvp\n'), ((1418, 1447), 'hknweb.events.models.Rsvp.objects.create', 'Rsvp.objects.create', ([], {}), '(**kwargs)\n', (1437, 1447), False, 'from hknweb.events.models import Event, EventType, Rsvp\n'), ((900, 914), 'django.utils.timezone.now', 'timezone.now', ([], {}), '()\n', (912, 914), False, 'from django.utils import timezone\n'), ((940, 954), 'django.utils.timezone.now', 'timezone.now', ([], {}), '()\n', (952, 954), False, 'from django.utils import timezone\n'), ((957, 984), 'datetime.timedelta', 'datetime.timedelta', ([], {'hours': '(2)'}), '(hours=2)\n', (975, 984), False, 'import datetime\n')]