from rest_framework import serializers
from tagulous.serializers.json import Serializer

from products.models import Product
from companies.serializers import CompanySerializer

from utils.tag_serializers import TagListSerializerField, TaggitSerializer, SingleTagSerializerField, SingleTag, TagList

class ProductSerializer(TaggitSerializer, serializers.ModelSerializer):

    tags = TagListSerializerField(required=False)
    category = SingleTagSerializerField(required=False) # main tag category
    attributes = TagListSerializerField(required=False)
    company = CompanySerializer(read_only=True)
    class Meta:
        model = Product
        fields = '__all__'


class SearchResultSerializer(TaggitSerializer, serializers.ModelSerializer):

    tags = TagListSerializerField(required=False)
    category = SingleTagSerializerField(required=False) # main tag category
    attributes = TagListSerializerField(required=False)
    company = CompanySerializer(read_only=True)
    rank = serializers.FloatField()

    class Meta:
        model = Product
        exclude = ['creator', ]


class TagFilterSerializer(TaggitSerializer, serializers.ModelSerializer):
    tags = TagListSerializerField(required=False)

    class Meta:
        model = TagList
        fields = '__all__'
