from marshmallow import Schema, fields, pprint, ValidationError

def validate_username(input_str):
    if len(input_str) < 4:
        raise ValidationError('Username must be between 4 and 20 characters.')
    if len(input_str) > 20:
        raise ValidationError('Username must be between 4 and 20 characters.')

def validate_password(input_str):
    if len(input_str) < 6: 
        raise ValidationError('Password must be between 6 and 36 characters.')
    if len(input_str) > 36:
        raise ValidationError('Password must be between 6 and 36 characters.')

class UserSchema(Schema):
    username = fields.Str(validate = validate_username, required=True)
    password = fields.Str(validate = validate_password, required=True)
    reputation = fields.Integer()

user_serializer = UserSchema( only=('id', 'reputation', 'username') )
