from rest_framework import serializers
from smartfarming.models.device import (
    MongoSCDData,
    MongoCBDData,
    MongoXYCBData,
    MongoBZYData
)

class MongoSCDDataSerializers(serializers.ModelSerializer):

    d_h_t = serializers.SerializerMethodField()

    def get_d_h_t(self, obj):
        device_data = eval(obj.device_data)
        device_data["addtime"] = obj.addtime
        return device_data

    class Meta:
        model = MongoSCDData
        fields = ["d_h_t"]


class MongoCBDDataSerializers(serializers.ModelSerializer):

    d_h_t = serializers.SerializerMethodField()

    def get_d_h_t(self, obj):
        device_data = eval(obj.device_data)
        device_data["addtime"] = obj.addtime
        return device_data

    class Meta:
        model = MongoCBDData
        fields = ["d_h_t"]


class MongoXYCBDataSerializers(serializers.ModelSerializer):

    d_h_t = serializers.SerializerMethodField()

    def get_d_h_t(self, obj):
        device_data = eval(obj.device_data)
        device_data["addtime"] = obj.addtime
        return device_data

    class Meta:
        model = MongoXYCBData
        fields = ["d_h_t"]


class MongoBZYDataSerializers(serializers.ModelSerializer):

    d_h_t = serializers.SerializerMethodField()

    def get_d_h_t(self, obj):
        device_data = eval(obj.device_data)
        device_data["addtime"] = obj.addtime
        return device_data

    class Meta:
        model = MongoBZYData
        fields = ["d_h_t"]