from django.shortcuts import render
from django.views.generic import DetailView, ListView
from django.views.generic.base import TemplateView
from django.views.generic.list import MultipleObjectMixin


from .models import Game, GameSystem, Genre, Developer, Publisher


class GameList(ListView):
    model = Game
    paginate_by = 20
    queryset = Game.objects.order_by("-created")[:20]


class GameDetail(DetailView):
    model = Game


class GamePlayDetail(DetailView):
    template_name = "games/game_play_detail.html"
    model = Game


class GameSystemDetail(DetailView, MultipleObjectMixin):
    model = GameSystem
    paginate_by = 20

    def get_context_data(self, **kwargs):
        object_list = Game.objects.filter(game_system=self.get_object())
        context = super(GameSystemDetail, self).get_context_data(
            object_list=object_list, **kwargs
        )
        return context


class GenreDetail(DetailView, MultipleObjectMixin):
    model = Genre
    paginate_by = 20

    def get_context_data(self, **kwargs):
        object_list = Game.objects.filter(genre=self.get_object())
        context = super(GenreDetail, self).get_context_data(
            object_list=object_list, **kwargs
        )
        return context


class PublisherDetail(DetailView):
    model = Publisher
    paginate_by = 20

    def get_context_data(self, **kwargs):
        object_list = Game.objects.filter(publisher=self.get_object())
        context = super(PublisherDetail, self).get_context_data(
            object_list=object_list, **kwargs
        )
        return context


class DeveloperDetail(DetailView):
    model = Developer
    paginate_by = 20

    def get_context_data(self, **kwargs):
        object_list = Game.objects.filter(developer=self.get_object())
        context = super(DeveloperDetail, self).get_context_data(
            object_list=object_list, **kwargs
        )
        return context
