from ipam.models import Role
from netbox.api.fields import RelatedObjectCountField
from netbox.api.serializers import OrganizationalModelSerializer

__all__ = (
    'RoleSerializer',
)


class RoleSerializer(OrganizationalModelSerializer):

    # Related object counts
    prefix_count = RelatedObjectCountField('prefixes')
    vlan_count = RelatedObjectCountField('vlans')
    asn_count = RelatedObjectCountField('asns')

    class Meta:
        model = Role
        fields = [
            'id', 'url', 'display_url', 'display', 'name', 'slug', 'weight', 'description', 'owner', 'comments', 'tags',
            'custom_fields', 'created', 'last_updated', 'prefix_count', 'vlan_count', 'asn_count',
        ]
        brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'prefix_count', 'vlan_count',
                        'asn_count')
