from apps.wpmw.models import Wpr, WprDefect
from apps.utils.serializers import CustomModelSerializer
from rest_framework import serializers
from apps.inm.serializers import MaterialBatchSerializer
from apps.wpm.serializers import WMaterialSerializer

class WprDefectSerializer(CustomModelSerializer):
    defect_name = serializers.CharField(source="defect.name", read_only=True)

    class Meta:
        model = WprDefect
        fields = "__all__"


class WprSerializer(CustomModelSerializer):
    material_name = serializers.StringRelatedField(
        source='material', read_only=True) 
    wprdefect = WprDefectSerializer(many=True, read_only=True)  

    class Meta:
        model = Wpr
        fields = '__all__'

class WprDetailSerializer(WprSerializer):
    mb_ = MaterialBatchSerializer(source='mb', read_only=True)
    wm_ = WMaterialSerializer(source='wm', read_only=True)


class WprNewSerializer(serializers.Serializer):
    year = serializers.IntegerField()
    month = serializers.IntegerField()
    material_start = serializers.CharField(label="物料ID")


class WproutSerializer(serializers.Serializer):
    id = serializers.CharField(label="wprId")
    number_out = serializers.CharField(label="对外编号", allow_null=True)


class WproutListSerializer(serializers.Serializer):
    items = WproutSerializer(many=True)

