from django.views.generic.edit import CreateView, UpdateView

from newsreader.news.collection.choices import RuleTypeChoices
from newsreader.news.collection.forms import SubRedditForm
from newsreader.news.collection.views.base import (
    CollectionRuleDetailMixin,
    CollectionRuleViewMixin,
)


class SubRedditCreateView(
    CollectionRuleViewMixin, CollectionRuleDetailMixin, CreateView
):
    form_class = SubRedditForm
    template_name = "news/collection/views/subreddit-create.html"


class SubRedditUpdateView(
    CollectionRuleViewMixin, CollectionRuleDetailMixin, UpdateView
):
    form_class = SubRedditForm
    template_name = "news/collection/views/subreddit-update.html"
    context_object_name = "subreddit"

    def get_queryset(self):
        queryset = super().get_queryset()
        return queryset.filter(type=RuleTypeChoices.subreddit)
