from typing import Optional

from flask_wtf import FlaskForm
from wtforms import StringField, SelectField, SubmitField
from wtforms.validators import DataRequired, Length, Email

from servicex.models import UserModel


class ProfileForm(FlaskForm):
    name = StringField('Full Name', validators=[DataRequired(), Length(0, 120)])
    email = StringField('Email', validators=[DataRequired(), Email()])
    institution = StringField('Institution', validators=[DataRequired()])
    experiment = SelectField('Experiment', validators=[DataRequired()],
                             choices=[("ATLAS", "ATLAS"), ("CMS", "CMS")],
                             default="ATLAS")
    submit = SubmitField('Save Profile')

    def __init__(self, user: Optional[UserModel] = None):
        super().__init__()
        if user:
            self.name.data = user.name
            self.email.data = user.email
            self.institution.data = user.institution
            self.experiment.data = user.experiment

[((17, 13, 17, 40), 'wtforms.SubmitField', 'SubmitField', ({(17, 25, 17, 39): '"""Save Profile"""'}, {}), "('Save Profile')", False, 'from wtforms import StringField, SelectField, SubmitField\n'), ((11, 48, 11, 62), 'wtforms.validators.DataRequired', 'DataRequired', ({}, {}), '()', False, 'from wtforms.validators import DataRequired, Length, Email\n'), ((11, 64, 11, 78), 'wtforms.validators.Length', 'Length', ({(11, 71, 11, 72): '0', (11, 74, 11, 77): '120'}, {}), '(0, 120)', False, 'from wtforms.validators import DataRequired, Length, Email\n'), ((12, 45, 12, 59), 'wtforms.validators.DataRequired', 'DataRequired', ({}, {}), '()', False, 'from wtforms.validators import DataRequired, Length, Email\n'), ((12, 61, 12, 68), 'wtforms.validators.Email', 'Email', ({}, {}), '()', False, 'from wtforms.validators import DataRequired, Length, Email\n'), ((13, 57, 13, 71), 'wtforms.validators.DataRequired', 'DataRequired', ({}, {}), '()', False, 'from wtforms.validators import DataRequired, Length, Email\n'), ((14, 55, 14, 69), 'wtforms.validators.DataRequired', 'DataRequired', ({}, {}), '()', False, 'from wtforms.validators import DataRequired, Length, Email\n')]