"""This module holds the factories for the ``surveys`` app"""

import factory

from mtp.apps.accounts.factories import TrainerFactory
from mtp.apps.trainings.factories import TrainingFactory

from .models import Choice, Pool, Question, Survey


class PoolFactory(factory.django.DjangoModelFactory):
    """Factory for the ``mtp.apps.surveys.models.Pool`` model.

    Attributes
    ----------
    id : `factory.Sequence``
    name : `factory.Sequence``
        The resulting names are of the form "pool-%d"
    author : sub-factory of ``mtp.apps.account.factories.TrainerFactory``
        It's a trainer by default but can be changed at creation time to be an admin.

    Notes
    -----
    - The ``description`` field is left empty.
    - The ``is_mandatory`` field is automatically set by django using its default value.
    - The ``is_global`` field is automatically set depending on the kind of author. See the
    ``save`` method of the model.
    """

    class Meta:
        model = Pool

    name = factory.Sequence(lambda n: 'pool-%d' % n)
    author = factory.SubFactory(TrainerFactory)


class QuestionFactory(factory.django.DjangoModelFactory):
    """Factory for the ``mtp.apps.surveys.models.Survey`` model.

    Attributes
    ----------
    id : `factory.Sequence``
    pool : sub-factory of ``mtp.apps.surveys.factories.PoolFactory``
    title : `factory.Sequence``
        The resulting titles are of the form "question-%d"

    Notes
    -----
    - The ``details``field  is left empty.
    - The ``question_type`` field is left empty.
    - The ``value_type`` field is left empty.

    """

    class Meta:
        model = Question

    pool = factory.SubFactory(PoolFactory)
    title = factory.Sequence(lambda n: 'question-%d' % n)


class ChoiceFactory(factory.django.DjangoModelFactory):
    """Factory for the ``mtp.apps.surveys.models.Choice`` model.

    Attributes
    ----------
    id : `factory.Sequence``
    question : sub-factory of ``mtp.apps.surveys.factories.QuestionFactory``
    label : `factory.Sequence``
        The resulting titles are of the form "choice-%d"

    Notes
    -----
    - The ``details``field  is left empty.
    - The ``value_number`` field is left empty.
    - The ``value_text`` field is left empty.

    """

    class Meta:
        model = Choice

    question = factory.SubFactory(QuestionFactory)
    label = factory.Sequence(lambda n: 'choice-%d' % n)


class SurveyFactory(factory.django.DjangoModelFactory):
    """Factory for the ``mtp.apps.surveys.models.Survey`` model.

    Attributes
    ----------
    id : `factory.Sequence``
    training :: sub-factory of ``mtp.apps.trainings.factories.TrainingFactory``
    trainer :: sub-factory of ``mtp.apps.accounts.factories.TrainerFactory``

    Notes
    -----
    The ``pools`` field (the list of pools for the survey) is left empty.
    """

    class Meta:
        model = Survey

    training = factory.SubFactory(TrainingFactory)
    trainer = factory.SubFactory(TrainerFactory)
