from rest_framework import serializers
from mosquito.models import Mosquito, MosqPost
from smart.api.serializers import SmartPushListSerializer


class MosqListSerializer(serializers.ModelSerializer):

    class Meta:
        model = Mosquito
        fields = [
            'name',
            'device_id',
            'region'
        ]


class MosqPostListSerializer(serializers.ModelSerializer):
    smart_push = SmartPushListSerializer(read_only=True)
    region = serializers.SerializerMethodField()

    class Meta:
        model = MosqPost
        fields = [
            'id',
            'mosq',
            'led',
            'energy',
            'region',
            'smart_push',
            'time',
        ]

    def get_region(self, obj):
        return obj.mosq.region
