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

from comment.models import Comment


class CommentBaseSerializer(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')
    status_display = serializers.CharField(read_only=True,
                                           source='get_status_display')
    last_ip = serializers.IPAddressField(read_only=True, source='user.last_ip')

    class Meta:
        """Serializer for model Comment"""
        model = Comment
        fields = [
            'id',
            'user_id',
            'is_mine',
            'created',
            'text',
            'mark',
            'nickname',
            'profile_pic',
            'status',
            'status_display',
            'last_ip',
        ]
        extra_kwargs = {
            'status': {'read_only': True},
        }
