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

from mtp.apps.brainstormers.models import (
    BrainstormerProposition, BrainstormerPropositionGroup,
    BrainstormerTemplate, PropositionWall, QuestionWall
)
from mtp.apps.import_export import resources


class BrainstormerPropositionResource(resources.Resource):
    """ Resource for BrainstormerProposition. """

    fields = (
        ('text', 'Proposition'),
        ('likes__count', 'Likes'),
        ('user__first_name', 'Author firstname'),
        ('user__last_name', 'Lastname')
    )

    def get_likes__count(obj):  # pylint: disable=no-self-argument
        """Return the aggregated pseudo field likes__count.

        Parameters
        ----------
        obj: BrainstormerProposition
            The ``BrainstormerProposition`` exported
        """
        return obj.likes__count


class BrainstormerGroupResource(resources.Resource):
    """ Resource for BrainstormerPropositionGroup. """

    fields = (
        ('name', 'Group Name'),
    )
    fields_to_get = ('name', 'brainstormer')
    header_comments = {
        'name': 'Name of group',
    }
    nested_resource = (('get_export_propositions', BrainstormerPropositionResource),)


class PropositionWallResource(resources.Resource):
    """Resource for PropositionWall."""

    fields = (
        ('name', 'PropositionWall title'),
    )
    nested_resource = (('get_export_groups', BrainstormerGroupResource),)


class QuestionWallResource(resources.Resource):
    """Resource for PropositionWall."""

    fields = (
        ('name', 'QuestionWall title'),
    )
    nested_resource = (('get_export_propositions', BrainstormerPropositionResource),)


class BrainstormerTemplateResource(resources.Resource):
    """ Resource for BrainstormerPropositionGroup. """

    fields_to_translate = ('name',)

resources.register(PropositionWall, PropositionWallResource)
resources.register(QuestionWall, QuestionWallResource)
resources.register(BrainstormerProposition, BrainstormerPropositionResource)
resources.register(BrainstormerPropositionGroup, BrainstormerGroupResource)
resources.register(BrainstormerTemplate, BrainstormerTemplateResource)
