from .models import PatentInfo, Papersecret, PatentRecord, PaperRecord, Platform, Platstanding
from apps.utils.serializers import CustomModelSerializer
from rest_framework import serializers
from django.db import transaction
from rest_framework.exceptions import ParseError
from apps.utils.constants import EXCLUDE_FIELDS
from apps.wf.serializers import TicketSimpleSerializer

class PatentInfoSerializer(CustomModelSerializer):
    create_by_name = serializers.CharField(source='create_by.name', read_only=True)
    belong_dept_name = serializers.CharField(source='belong_dept.name', read_only=True)
    ticket_ = TicketSimpleSerializer(source='ticket', read_only=True)
    class Meta:
        model = PatentInfo
        fields = '__all__'
        read_only_fields = EXCLUDE_FIELDS


class PaperSeSerializer(CustomModelSerializer):
    create_by_name = serializers.CharField(source='create_by.name', read_only=True)
    belong_dept_name = serializers.CharField(source='belong_dept.name', read_only=True)
    ticket_ = TicketSimpleSerializer(source='ticket', read_only=True)
    class Meta:
        model = Papersecret
        fields = '__all__'
        read_only_fields = EXCLUDE_FIELDS


class PatentRecordSerializer(CustomModelSerializer):
    create_by_name = serializers.CharField(source='create_by.name', read_only=True)
    belong_dept_name = serializers.CharField(source='belong_dept.name', read_only=True)
    patent_name = serializers.CharField(source='patent.name', read_only=True, label="专利名称")
    class Meta:
        model = PatentRecord
        fields = '__all__'
        read_only_fields = EXCLUDE_FIELDS

class PaperRecordSerializer(CustomModelSerializer):
    create_by_name = serializers.CharField(source='create_by.name', read_only=True)
    belong_dept_name = serializers.CharField(source='belong_dept.name', read_only=True)
    paper_name = serializers.CharField(source='paper.paper_name', read_only=True, label="论文名称")
    class Meta:
        model = PaperRecord
        fields = '__all__'
        read_only_fields = EXCLUDE_FIELDS

class PlatformSerializer(CustomModelSerializer):
    create_by_name = serializers.CharField(source='create_by.name', read_only=True)
    ticket_ = TicketSimpleSerializer(source='ticket', read_only=True)
    class Meta:
        model = Platform
        fields = '__all__'
        read_only_fields = EXCLUDE_FIELDS

class PlatstandingSerializer(CustomModelSerializer):
    platinfo_ = PlatformSerializer(source='platinfo', read_only=True)
    plat_name = serializers.CharField(source='platinfo.name', read_only=True, label="平台名称")
    create_by_name = serializers.CharField(source='create_by.name', read_only=True)
    class Meta:
        model = Platstanding
        fields = '__all__'
        read_only_fields = EXCLUDE_FIELDS

