from rest_framework import serializers
from django.contrib.auth.models import User
from Hub.models import Beacon, BeaconManager, Category, Site, UserProject


class SiteSerializer(serializers.HyperlinkedModelSerializer):
    author = serializers.HyperlinkedRelatedField(view_name='user-detail', queryset=User.objects.all())
    class Meta:
        model = Site
        fields = ('id', 'url', 'link_url', 'description', 'category', 'author')


class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('id', 'url' ,'username')


class FullSiteSerializer(serializers.HyperlinkedModelSerializer):
    author = UserSerializer()


    class Meta:
        model = Site
        fields = ('id', 'url', 'link_url', 'description', 'category', 'author')


class BeaconSerializer(serializers.HyperlinkedModelSerializer):

    class Meta:
        model = Beacon
        fields = ('id', 'url', 'uuid', 'name', 'description', 'longitude', 'latitude', 'beacon_manager')

class BeaconManagerSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = BeaconManager
        fields = ('id', 'url', 'sites', 'beacon')

class CategorySerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Category
        fields = ('id', 'url', 'name', 'private')

class FullSiteSerializer(serializers.HyperlinkedModelSerializer):
    author = UserSerializer()
    category = CategorySerializer(many=True)

    class Meta:
        model = Site
        fields = ('id', 'url', 'link_url', 'description', 'category', 'author')

class FullBeaconManagerSerializer(serializers.HyperlinkedModelSerializer):
    sites = FullSiteSerializer(many=True)
    beacon = BeaconSerializer()
    class Meta:
        model = BeaconManager
        fields = ('id', 'url', 'sites', 'beacon')

class FullUserProjectSerializer(serializers.HyperlinkedModelSerializer):
    author = UserSerializer()
    beacon_managers = FullBeaconManagerSerializer(many=True)

    class Meta:
        model = UserProject
        fields = ('id', 'url', 'author', 'beacon_managers', 'name', 'description')

class UserProjectSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = UserProject
        fields = ('id', 'url', 'author', 'beacon_managers', 'name', 'description')