from rest_framework import serializers
from interest.models import Interest, LANGUAGE_CHOICES, STYLE_CHOICES


class InterestSerializer(serializers.ModelSerializer):
    class Meta:
        model=Interest
        fields = ('id','name','description','category','subcategory','linenos','language','style')

    #id = serializers.IntegerField(read_only=True)
    #name = serializers.CharField(required=False, allow_blank=True, max_length=100)
    #description = serializers.CharField(style={'base_template': 'textarea.html'})
    #category = serializers.CharField(style={'base_template': 'textarea.html'})
    #subcategory = serializers.CharField(style={'base_template': 'textarea.html'})
    #linenos = serializers.BooleanField(required=False)
    #language = serializers.ChoiceField(choices=LANGUAGE_CHOICES, default='python')
    #style = serializers.ChoiceField(choices=STYLE_CHOICES, default='friendly')

    def create(self, validated_data):
        """
        Create and return a new `Snippet` instance, given the validated data.
        """
        return Interest.objects.create(**validated_data)

    def update(self, instance, validated_data):
        """
        Update and return an existing `Snippet` instance, given the validated data.
        """
        instance.name = validated_data.get('title', instance.name)
        instance.description = validated_data.get('code', instance.description)
        instance.category = validated_data.get('code', instance.category)
        instance.subcategory = validated_data.get('code', instance.subcategory)
        instance.linenos = validated_data.get('linenos', instance.linenos)
        instance.language = validated_data.get('language', instance.language)
        instance.style = validated_data.get('style', instance.style)
        instance.save()
        return instance