""" Resource used for import/export workshops data.
A documentation about Resource is available in import_export.resources module.
"""

from mtp.apps.import_export import resources
from mtp.apps.workshops.models import (
    Workshop, WorkshopStepQuestion, WorkshopStepQuestionAnswer, WorkshopStep
)


class WorkshopStepQuestionAnswerResource(resources.Resource):
    fields = (
        ('label', 'Answer text'),
        ('is_correct', 'Good answer?'),
        ('points', 'Answer Points'),
        ('color', 'Answer Color')
    )
    fields_to_translate = ('label',)
    fk_fields_to_translate = ('question',)


class WorkshopStepQuestionResource(resources.Resource):
    fields = (
        ('step_name', 'type'),
        ('title', 'Question title'),
        'dimensions__code 1',
        'dimensions__code 2',
        'dimensions__code 3'
    )
    fields_to_translate = ('title',)
    fk_fields_to_translate = ('answers',)
    nested_resource = (
        ('answers', WorkshopStepQuestionAnswerResource),
    )

    @staticmethod
    def get_step_name(obj):
        if obj.is_multiple_choices:
            return 'multiple'
        else:
            return 'unique'


class WorkshopResource(resources.Resource):
    fields = (
        ('name', 'Workshop name'),
        ('is_steps_order_random', 'Random step order'),
        ('is_questions_answers_order_random', 'Random answers order'),
        ('weight', 'Weight')
    )
    fields_to_get = ('name', 'training')
    fields_to_translate = ('name',)
    fk_fields_to_translate = ('steps',)
    nested_resource = (
        ('steps', WorkshopStepQuestionResource),
    )


class WorkshopStepResource(resources.Resource):
    fields_to_translate = True


resources.register(WorkshopStepQuestion, WorkshopStepQuestionResource)
resources.register(Workshop, WorkshopResource)
resources.register(WorkshopStep, WorkshopStepResource)
resources.register(WorkshopStepQuestionAnswer, WorkshopStepQuestionAnswerResource)
