from rest_framework import serializers

from .models import Enterprise,EnterpriseAddress
from apps.system.serializers import DictSerializer


class EnterpriseSerializer(serializers.ModelSerializer):
    class Meta:
        model = Enterprise
        fields = '__all__'
class EnterpriseListSerializer(serializers.ModelSerializer):
    type = DictSerializer()
    economy_class = DictSerializer()
    class Meta:
        model = Enterprise
        fields = ['id','query_code', 'code', 'name','ename','type','legal','build_time','person_count','ceramics_output','gassets','linkman1_name','linkman1_tel','linkman1_mobile','country_code','credit_code','professional','all_person','economy_class','economy_type','linkman1_duty','business_type']
    @staticmethod
    def setup_eager_loading(queryset):
        """ Perform necessary eager loading of data. """
        queryset = queryset.select_related('type','economy_class')
        return queryset
    
    def get_cert_type(self, obj):
        return obj.get_cert_type_display()
class EnterpriseAddressSerializer(serializers.ModelSerializer):
    class Meta:
        model = EnterpriseAddress
        fields = '__all__'
   
    
   