from rest_framework import serializers

from authentication.models import ToolshedUser, Group


class OwnerSerializer(serializers.ReadOnlyField):
    class Meta:
        model = ToolshedUser
        fields = ['username', 'domain']

    def to_representation(self, value):
        return value.username + '@' + value.domain


class GroupOwnerSerializer(serializers.ReadOnlyField):
    class Meta:
        model = Group
        fields = ['name', 'domain']

    def to_representation(self, value):
        return f"#{value.name}@{value.domain}"
