"""This module provides the ``TrainingClientOptions`` model for the ``trainings`` app"""

from django.core.urlresolvers import reverse
from django.db import models
from django.utils.translation import ugettext_lazy as _

from mtp.discrete_apps.versionable.models import Dependency

from mtp.apps.common.utils import classproperty
from mtp.apps.sync.models import Syncable


class TrainingClientOptions(Dependency, Syncable):
    """Django model representing a set of options for a ``Training``

    Attributes
    ----------
    training : django ``OneToOneField`` to a ``Training`` instance
        The training the options belongs to.
    activate_show_results : django ``BooleanField`` field
        Activate the "show results" menu item for the training
    activate_activity_launcher : django ``BooleanField`` field
        Activate the creation "on the fly" of new activities on the clients

    Notes
    -----
    This model is a ``Dependency`` of the ``Training``.

    """

    training = models.OneToOneField(
        'trainings.Training',
        related_name='client_options',
        on_delete=models.CASCADE
    )

    activate_show_results = models.BooleanField(
        default=False,
        verbose_name=_('Activate "Show results" interface'),
        help_text=_('"Show results" interface allows the trainer to review '
                    'trainee results based on the competences and qualitatives feedbacks')
    )
    activate_activity_quickcreation = models.BooleanField(
        default=True,
        verbose_name=_('Activate "In-session activity creation"'),
        help_text=_('"In-session activity creation" allows the trainer to create new '
                    'activities during the training session. It includes new photostory, '
                    'new buzzer, new metaplan & new brainstormer')
    )
    activate_qrcode_launcher = models.BooleanField(
        default=False,
        verbose_name=_('Activate "QR code launcher"'),
        help_text=_('"QR code launcher" allows trainees to launch activities when they scan'
                    'QR codes with their device. So activating "QR code launcher" creates a QR'
                    'code for each activity of the training and activate the functionality'
                    '"Code Scanner" on the trainee iPad.')
    )

    non_lockable_fields = Dependency.non_lockable_fields + Syncable.non_lockable_fields

    @classproperty
    def versionable_link(cls):  # pylint: disable=no-self-argument
        """Defines the link the the ``Versionable`` object"""

        from . import Training
        return Training, 'training'

    def get_edit_url(self):
        """Get the url to edit the options

        Returns
        -------
        string
            The wanted url.

        """
        return reverse('trainings:options-edit', kwargs={
            'options_uuid': self.pk,
            'training_uuid': self.training.pk
        })
