from django.contrib.auth.models import User
from rest_framework import serializers
from pentagram.models import Photo
from pentagram.models import Comment
from pentagram.models import Like

class PhotoSerializer(serializers.ModelSerializer):
    class Meta:
        model = Photo
        fields = ('id', 'user', 'photo')

    def create(self, validated_data):
        photo = Photo.objects.create(**validated_data)
        return photo

class CommentSerializer(serializers.ModelSerializer):
    class Meta:
        model = Comment
        fields = ('id', 'user', 'photo', 'comment')

    def create(self, validated_data):
        comment = Comment.objects.create(**validated_data)
        return comment

class LikeSerializer(serializers.ModelSerializer):
    class Meta:
        model = Like
        fields = ('id', 'user', 'photo')

    def create(self, validated_data):
        like = Comment.objects.create(**validated_data)
        return like

class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ('id', 'username', 'password', 'email')

    def create(self, validated_data):
        user = User.objects.create(**validated_data)
        user.set_password(validated_data["password"])
        user.save()
        return user