"""This module holds the model serializers for the ``roleplays`` app"""

from rest_framework import serializers

from .models import Criterion, Evaluation, Exercise, Rating


class CriterionSerializer(serializers.ModelSerializer):
    """Serializer for the ``Criterion`` model."""

    class Meta:
        model = Criterion
        fields = (

            # TODO

        )


class ExerciseSerializer(serializers.ModelSerializer):
    """Serializer for the ``Exercise`` model."""

    criteria = CriterionSerializer(many=True)

    class Meta:
        model = Exercise
        fields = (

            # TODO

        )


class EvaluationSerializer(serializers.ModelSerializer):
    """Serializer for the ``Evaluation`` model."""

    exercises = ExerciseSerializer(many=True)

    class Meta:
        model = Evaluation
        fields = (

            # TODO

        )


class RatingListSerializer(serializers.ListSerializer):
    """ListSerializer for multiple ``Rating`` models."""


class RatingSerializer(serializers.ModelSerializer):
    """Serializer for the ``Rating`` model.

    Example
    -------

    For multiple new ``Rating`` instances.
    Given that we already have a ``session`` and a ``trainee``
    in the context.

    >>> ratings = [
    >>>     { # Criterion quantitative
    >>>         'criterion': criterion1_id,
    >>>         'score': 2
    >>>     },
    >>>     { # Criterion qualitative
    >>>         'criterion': criterion2_id,
    >>>         'score': 1
    >>>     }
    >>> ]
    >>>
    >>> serialized_ratings = RatingSerializer(data=ratings, many=True)
    >>>
    >>> ratings = serialized_ratings.save()

    See also
    --------

    ``mtp.apps.evaluations.managers.RatingManager.save_rating`` method.

    """

    def create(self, validated_data):
        rating = Rating(**validated_data)
        Rating.objects.save_rating(rating)

        return rating

    class Meta:
        model = Rating
        fields = (
            'criterion',
            'text',
            'score'
        )

