from flask_wtf import FlaskForm
from wtforms import SubmitField, SelectField, DateField, IntegerField, StringField
from wtforms.validators import DataRequired, Length, ValidationError
from flask_wtf.file import FileField, FileAllowed
import minibase.database.utils as dbUtils


class selectProjectForm(FlaskForm):  # Defines the form class to be used for the user registretion
    # Decalarion of the fields for the form and it's propereties
    project = SelectField('Project Name', validators=[DataRequired()])
    submit = SubmitField('Show Project details')
    submit_to_element = SubmitField('Continue to Element Selection')


class projectRegisterForm(FlaskForm):
    name = StringField('Project Name', validators=[DataRequired(), Length(min=3, max=20)])
    description = StringField('Project Description', validators=[DataRequired(), Length(min=3, max=300)])
    company = SelectField('Company name', validators=[DataRequired()])
    industry = SelectField('industry', validators=[DataRequired()])
    status = SelectField('Status', validators=[DataRequired()])
    qtePrototype = IntegerField('Prototye Quantity', validators=[DataRequired()])
    datePrototype = DateField('Prototyping Date', validators=[DataRequired()])
    qteStart = IntegerField('Starting Quantity', validators=[DataRequired()])
    dateStart = DateField('Firts Starting Date', validators=[DataRequired()])
    qteProduction = IntegerField('Production Quantity', validators=[DataRequired()])
    dateProduction = DateField('Production Date', validators=[DataRequired()])
    picture = FileField('Update Project Picture', validators=[FileAllowed(['jpg', 'png'])])
    submit = SubmitField('Register Project')


class projectUpdateForm(FlaskForm):
    description = StringField('Description', validators=[DataRequired(), Length(min=3, max=300)])
    industry = SelectField('industry', validators=[DataRequired()])
    status = SelectField('Status', validators=[DataRequired()])
    responsible = SelectField('Repsonsible', validators=[DataRequired()])
    qtePrototype = IntegerField('Prototye Quantity', validators=[DataRequired()])
    datePrototype = DateField('Prototyping Date', validators=[DataRequired()])
    qteStart = IntegerField('Starting Quantity', validators=[DataRequired()])
    dateStart = DateField('Starting Date', validators=[DataRequired()])
    qteProduction = IntegerField('Production Quantity', validators=[DataRequired()])
    dateProduction = DateField('Production Date', validators=[DataRequired()])
    picture = FileField('Picture', validators=[FileAllowed(['jpg', 'png'])])
    submit = SubmitField('Update Project')


class selectElementForm(FlaskForm):  # Defines the form class to be used for the user registretion
    # Decalarion of the fields for the form and it's propereties
    element = SelectField('Element Name', validators=[DataRequired()])
    submit = SubmitField('Show Element details')


class elementRegisterForm(FlaskForm):
    project = SelectField('Project Name', validators=[DataRequired()])
    name = StringField('Element Name', validators=[DataRequired(), Length(min=3, max=20)])
    description = StringField('Description', validators=[DataRequired(), Length(min=3, max=300)])
    qtePerProject = IntegerField('Quantity per project', validators=[DataRequired()])
    status = SelectField('Status', validators=[DataRequired()])
    company_to_ship = SelectField('Company to ship', validators=[DataRequired()])
    owner = SelectField('Owner', validators=[DataRequired()])
    submit = SubmitField('Register Element')


class elementUpdateForm(FlaskForm):
    description = StringField('Description', validators=[DataRequired(), Length(min=3, max=300)])
    qtePerProject = IntegerField('Quantity per project', validators=[DataRequired()])
    status = SelectField('Status', validators=[DataRequired()])
    company_to_ship = SelectField('Status', validators=[DataRequired()])
    owner = SelectField('Owner', validators=[DataRequired()])
    submit = SubmitField('Update Element')
