"""Common serializers for app comment."""
from rest_framework import serializers

from comment.models import Comment


class CommentSerializer(serializers.ModelSerializer):
    """Comment serializer"""
    nickname = serializers.CharField(read_only=True,
                                     source='user.username')
    is_mine = serializers.BooleanField(read_only=True)
    profile_pic = serializers.URLField(read_only=True,
                                       source='user.cropped_image_url')

    class Meta:
        """Serializer for model Comment"""
        model = Comment
        fields = [
            'id',
            'user_id',
            'is_mine',
            'created',
            'text',
            'mark',
            'nickname',
            'profile_pic'
        ]


class CommentRUDSerializer(CommentSerializer):
    """Retrieve/Update/Destroy comment serializer."""
    class Meta(CommentSerializer.Meta):
        """Meta class."""
        fields = [
            'id',
            'created',
            'text',
            'mark',
            'nickname',
            'profile_pic',
        ]
