"""This module holds the views related to the ``QuestionWall`` model"""

from django.utils.translation import ugettext_lazy as _
from django.views import generic

from mtp.apps.common.views_utils import AjaxResponseMixin
from mtp.apps.trainings.views.activities import (
    TrainingActivityCreateBase,
    TrainingActivityDetailBase,
    TrainingActivityEditBase,
)

from ..models import WordCloud


class WordCloudBase(TrainingActivityDetailBase):
    """Base view to use on all views related to the ``WordCloud`` model.

    Define the queryset to use for the current user.

    """

    def get_queryset(self):
        """Get all ``WordCloud`` instances the current user is allowed to see.

        The user can only see wordclouds instance he own.
        Also excludes deleted wordclouds from the result.

        Returns
        -------
        Queryset of ``mtp.apps.ideas.models.WordCloud``
            A lazy queryset with the wanted wordclouds.

        """

        return super().get_queryset().instance_of(WordCloud)

    def get_success_url(self):
        """Get the url where to go back when an action is done on a ``WordCloud``"""

        return self.object.get_detail_url()


class WordCloudEditBase(AjaxResponseMixin, WordCloudBase):
    """Base view to create or edit a given instance of ``WordCloud``"""

    model = WordCloud
    fields = ['name', 'description', 'is_anonymous']
    pk_url_kwarg = 'wordcloud_uuid'


class WordCloudDetailView(WordCloudEditBase, generic.DetailView):
    """Detail View for a ``Brainstorming`` instance"""

    template_name = 'ideas/idea_activity_detail.html'


class WordCloudCreateView(WordCloudEditBase, TrainingActivityCreateBase):
    """View to create a new ``WordCloud`` instance"""

    success_message = _('Your Wordcloud was successfully created.')


class WordCloudUpdateView(WordCloudEditBase, TrainingActivityEditBase):
    """View to update an existing ``WordCloud`` instance"""

    success_message = _('Your Wordcloud was successfully updated.')
