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

import datetime
import factory

from mtp.apps.accounts.factories import TraineeFactory
from mtp.apps.trainings.factories import TrainingFactory, TrainingSession

from .models import Criterion, Rating, Roleplay, Step


class RoleplayFactory(factory.django.DjangoModelFactory):
    """Factory for the ``mtp.apps.roleplays.models.Roleplay`` model.

    Attributes
    ----------
    id : ``factory.Sequence``
    name : ``factory.Sequence``
        The resulting names are of the form "roleplay-%d"
    training : sub-factory of ``mtp.apps.training.factories.TrainingFactory``
    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 ``are_criteria_ratings_editable`` field is automatically set by django using
    its default value (True).
    - The ``criteria_rating_scale`` field is automatically set by django using
    its default value (2).
    """

    class Meta:
        model = Roleplay

    name = factory.Sequence(lambda n: 'roleplay-%d' % n)
    training = factory.SubFactory(TrainingFactory)


class AssessingRoleplayFactory(RoleplayFactory):
    is_assessing = True


class StepFactory(factory.django.DjangoModelFactory):
    """Factory for the ``mtp.apps.roleplays.models.Step`` model.

    Attributes
    ----------
    id: ``factory.Sequence``
    name: ``factory.Sequence``
        The resulting names are of the form "step-%d"
    roleplay : sub-factory of ``mtp.apps.roleplays.factories.RoleplayFactory``

    Notes
    -----
    - The ``description`` field is left empty.
    """

    class Meta:
        model = Step

    name = factory.Sequence(lambda n: 'step-%d' % n)
    duration = factory.Sequence(lambda n: datetime.timedelta(seconds=n))
    roleplay = factory.SubFactory(RoleplayFactory)


class CriterionFactory(factory.django.DjangoModelFactory):
    """Factory for the ``mtp.apps.roleplays.models.Criterion``model.

    Attributes
    ----------
    id: ``factory.Sequence``
    name: ``factory.Sequence``
        The resulting names are of the form "criterion-%d"
    step: sub-factory of ``mtp.apps.roleplays.factories.StepFactory``

    Notes
    -----
    - The ``description`` field is left empty.
    - The ``criterion_type`` field is automatically set by django using
    its default value (``mtp.apps.roleplays.models.Step.CRITERION_TYPES.QUANTITATIVE``).
    """

    class Meta:
        model = Criterion

    name = factory.Sequence(lambda n: 'criterion-%d' % n)
    step = factory.SubFactory(StepFactory)


class AssessingCriterionFactory(CriterionFactory):
    is_assessing = True


class RatingFactory(factory.django.DjangoModelFactory):
    """Factory for the ``mtp.apps.roleplays.models.Rating``model.

    Attributes
    ----------
    id: ``factory.Sequence``
    training_session: sub-factory of ``mtp.apps.trainings.factories.TrainingSessionFactory``
    trainee: sub-factory of ``mtp.apps.accounts.factories.TraineeFactory``
    criterion: sub-factory of ``mtp.apps.roleplays.factories.CriterionFactory``
    text: ``factory.Sequence``
        The resulting tests are of the form "rating-%d"
    score: ``factory.Sequence``
        The resulting scores are of the form "%d"

    """

    class Meta:
        model = Rating

    training_session = factory.SubFactory(TrainingSession)
    trainee = factory.SubFactory(TraineeFactory)
    criterion = factory.SubFactory(CriterionFactory)
    text = factory.Sequence(lambda n: 'rating-%d' % n)
    score = factory.Sequence(lambda n: n)