from rest_framework import serializers
from chat.models import Message
from helpdesk.models import Ticket
from helpdesk.serializers.user_serializers import SimpleUserSerializer

class MessageSerializer(serializers.ModelSerializer):
    sender = SimpleUserSerializer(read_only=True)

    class Meta:
        model = Message
        fields = ['id', 'ticket', 'sender', 'content', 'message_type', 'timestamp']
        read_only_fields = fields

class MessageCreateSerializer(serializers.ModelSerializer):
    class Meta:
        model = Message
        fields = ['ticket', 'content', 'message_type']

    def validate_content(self, value):
        if not value.strip():
            raise serializers.ValidationError("Content cannot be empty.")
        return value
