# Path: authentication/models.py
# class User(AbstractUser):
#     tagline = StringField(max_length=140, required=False)
#     created_at = DateTimeField(default=datetime.utcnow)
#     updated_at = DateTimeField()
# 
# 
#     USERNAME_FIELD = 'email'
#     REQUIRED_FIELDS = ['username']


from datetime import datetime
from rest_framework_mongoengine import serializers
from authentication.models import User
# coding=utf-8


class UserSerializer(serializers.DocumentSerializer):
    password = serializers.drf_fields.CharField(write_only=True, required=False)
    confirm_password = serializers.drf_fields.CharField(write_only=True, required=False)
    tagline = serializers.drf_fields.CharField(max_length=140, required=False, allow_blank=True, allow_null=True)
    first_name = serializers.drf_fields.CharField(max_length=40, required=False, allow_blank=True, allow_null=True)
    last_name = serializers.drf_fields.CharField(max_length=40, required=False, allow_blank=True, allow_null=True)

    class Meta:
        model = User
        depth = 1
        fields = ('id', 'email', 'username', 'created_at', 'updated_at', 'first_name', 'last_name',
                  'tagline', 'password', 'confirm_password')
        read_only_fields = ('created_at', 'updated_at',)

    def create(self, validated_data):

# Path: authentication/models.py
# class User(AbstractUser):
#     tagline = StringField(max_length=140, required=False)
#     created_at = DateTimeField(default=datetime.utcnow)
#     updated_at = DateTimeField()
# 
# 
#     USERNAME_FIELD = 'email'
#     REQUIRED_FIELDS = ['username']


# Path: authentication/serializers.py
from datetime import datetime
from rest_framework_mongoengine import serializers
from authentication.models import User

# coding=utf-8


class UserSerializer(serializers.DocumentSerializer):
    password = serializers.drf_fields.CharField(write_only=True, required=False)
    confirm_password = serializers.drf_fields.CharField(write_only=True, required=False)
    tagline = serializers.drf_fields.CharField(max_length=140, required=False, allow_blank=True, allow_null=True)
    first_name = serializers.drf_fields.CharField(max_length=40, required=False, allow_blank=True, allow_null=True)
    last_name = serializers.drf_fields.CharField(max_length=40, required=False, allow_blank=True, allow_null=True)

    class Meta:
        model = User
        depth = 1
        fields = ('id', 'email', 'username', 'created_at', 'updated_at', 'first_name', 'last_name',
                  'tagline', 'password', 'confirm_password')
        read_only_fields = ('created_at', 'updated_at',)

    def create(self, validated_data):

        user = User(**validated_data)