from rest_framework import serializers
from .models import PdfOperation


class PdfOperationSerializer(serializers.ModelSerializer):
    created_by_email = serializers.EmailField(source='created_by.email', read_only=True)
    operation_label = serializers.CharField(source='get_operation_type_display', read_only=True)

    class Meta:
        model = PdfOperation
        fields = [
            'id', 'operation_type', 'operation_label', 'original_filename',
            'result_filename', 'original_size', 'result_size',
            'page_count', 'options', 'created_by', 'created_by_email',
            'created_at'
        ]
        read_only_fields = ['id', 'created_at']


class PdfOperationCreateSerializer(serializers.ModelSerializer):
    class Meta:
        model = PdfOperation
        fields = [
            'id', 'operation_type', 'original_filename', 'result_filename',
            'original_size', 'result_size', 'page_count', 'options'
        ]
        read_only_fields = ['id']
