# -*- coding: utf-8 -*-
#
from rest_framework import serializers

from ..models import Domain, Gateway


class DomainSerializer(serializers.ModelSerializer):
    asset_count = serializers.SerializerMethodField()
    gateway_count = serializers.SerializerMethodField()

    class Meta:
        model = Domain
        fields = '__all__'

    @staticmethod
    def get_asset_count(obj):
        return obj.assets.count()

    @staticmethod
    def get_gateway_count(obj):
        return obj.gateway_set.all().count()


class GatewaySerializer(serializers.ModelSerializer):

    class Meta:
        model = Gateway
        fields = '__all__'
