from rest_framework import serializers
from .models import HelpdeskSubmission

class HelpdeskSubmissionSerializer(serializers.ModelSerializer):
    class Meta:
        model = HelpdeskSubmission
        fields = ['user', 'title', 'description', 'image']

    def create(self, validated_data):
        # Automatically set the user field to the logged-in user
        user = self.context['request'].user
        validated_data['user'] = user
        return super().create(validated_data)
