# plugins/auth/forms.py

from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField, IntegerField
from wtforms.validators import (
    DataRequired, Email, Length, EqualTo, Regexp, NumberRange
)

class RegistrationForm(FlaskForm):
    username        = StringField(
        'Username',
        validators=[DataRequired(), Length(min=3, max=25)]
    )
    email           = StringField(
        'Email',
        validators=[DataRequired(), Email(), Length(max=120)]
    )
    invitation_code = StringField(
        'Invitation Code',
        validators=[DataRequired(),
                    Length(min=36, max=36,
                           message="Invitation code must be 36 characters.")]
    )
    password        = PasswordField(
        'Password',
        validators=[DataRequired(), Length(min=6)]
    )
    confirm         = PasswordField(
        'Confirm Password',
        validators=[DataRequired(),
                    EqualTo('password', message='Passwords must match.')]
    )
    submit          = SubmitField('Register')


class LoginForm(FlaskForm):
    email       = StringField(
        'Email',
        validators=[DataRequired(), Email(), Length(max=120)]
    )
    password    = PasswordField(
        'Password',
        validators=[DataRequired()]
    )
    remember_me = BooleanField('Remember me')
    submit      = SubmitField('Log In')


class InviteForm(FlaskForm):
    email   = StringField(
        'Recipient Email',
        validators=[DataRequired(), Email(), Length(max=120)]
    )
    submit  = SubmitField('Send Invite')


class AdjustInvitesForm(FlaskForm):
    delta  = IntegerField(
        'Adjustment',
        validators=[DataRequired(), NumberRange()]
    )
    submit = SubmitField('Adjust Invites')
