from smartfarming.models.pests_bank import MongoPestBank
from smartfarming.models.pest_count import MongoCBDPestWarning
from smartfarming.models.weather import MongoQXZ_Alarm_Log_New
from smartfarming.models.device import MongoDevice
from rest_framework import serializers


class PestBankSerializers(serializers.ModelSerializer):

    class Meta:
        model = MongoPestBank
        fields = "__all__"


class MongoCBDPestWarningSerializers(serializers.ModelSerializer):

    class Meta:
        model = MongoCBDPestWarning
        fields = "__all__"


class MongoQXZAlarmLogNewSerializers(serializers.ModelSerializer):

    device_id = serializers.SerializerMethodField()

    def get_device_id(self,obj):
        return MongoDevice.objects.get(id=obj.device_id).device_id

    class Meta:
        model = MongoQXZ_Alarm_Log_New
        fields = [
            "id",
            "device_id",
            "user_id",
            "warning_name",
            "ekey",
            "warning_content",
            "send_user",
            "status",
            "upl_time",
        ]