# coding=utf-8
from rest_framework import serializers
from .models import InspectionOrder
from ...upload.serializers import UploadSerializer


class InspectionOrderSerializer(serializers.ModelSerializer):
    status = serializers.CharField(source='get_status_display', read_only=True)
    user_name = serializers.CharField(source='user.employee.name', read_only=True)
    user_tel = serializers.CharField(source='user.employee.tel', read_only=True)
    repair_type = serializers.CharField(source='repair_type.name', read_only=True)
    repair_order = serializers.CharField(source='repair_order.no', read_only=True)
    turn_repair_user_name = serializers.CharField(source='turn_repair_user.employee.name', read_only=True)
    images = serializers.SerializerMethodField()
    status_text = serializers.CharField(source='get_status_display', read_only=True)

    def get_images(self, obj):
        return UploadSerializer(obj.images, many=True).data

    class Meta:
        model = InspectionOrder
        fields = (
            'id', 'status', 'device_address', 'no', 'problem', 'create_time', 'turn_repair_time', 'user_name',
            'user_tel',    'device_name', 'repair_type', 'repair_order','status_text', 'turn_repair_user_name', 'images')
