from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired, ValidationError
from minibase.database.models import Person_role, Person_competence
from minibase.database.models import Company_legal_entity, Company_relation, Company_status
from minibase.database.models import Industry, Note_status
from minibase.database.models import Project_status
from minibase.database.models import Product_status, Product_physical, Product_packaging, Product_eligibility, Product_classification, Product_domain, Product_category, Product_sub_category
import minibase.admin.utils as adminUtils


class industryRegisterForm(FlaskForm):  # Defines the form class to be used for the user registretion
    # Decalarion of the fields for the form and it's propereties
    name = StringField('Name', validators=[DataRequired()])
    description = StringField('Description', validators=[DataRequired()])
    submit = SubmitField('Register Industry')

    # Queries to be made in order to validate the form : If Relation Type exitst  # Case Insensistive
    def validate_name(self, name):
        if adminUtils.doesNameExistsCi(Product_status, name.data):
            raise ValidationError('That Industry Type is already registered')


class compRelationForm(FlaskForm):  # Defines the form class to be used for the user registretion
    # Decalarion of the fields for the form and it's propereties
    name = StringField('Name', validators=[DataRequired()])
    description = StringField('Description', validators=[DataRequired()])
    submit = SubmitField('Register Company Relation')

    # Queries to be made in order to validate the form : If Relation Type exitst  # Case Insensistive
    def validate_name(self, name):
        if adminUtils.doesNameExistsCi(Company_relation, name.data):
            raise ValidationError('That Company Relation Type is already registered')


class compLegalEntityForm(FlaskForm):  # Defines the form class to be used for the user registretion
    # Decalarion of the fields for the form and it's propereties
    name = StringField('Name', validators=[DataRequired()])
    description = StringField('Description', validators=[DataRequired()])
    submit = SubmitField('Register Company Legal Entity')

    # Queries to be made in order to validate the form : If Legal Entity exitst  # Case Insensistive
    def validate_name(self, name):
        if adminUtils.doesNameExistsCi(Company_legal_entity, name.data):
            raise ValidationError('That Company Legal Entity is already registered')

class compStatusForm(FlaskForm):  # Defines the form class to be used for the user registretion
    # Decalarion of the fields for the form and it's propereties
    name = StringField('Name', validators=[DataRequired()])
    description = StringField('Description', validators=[DataRequired()])
    submit = SubmitField('Register Company Status')

    # Queries to be made in order to validate the form : If Person Role exitst  # Case Insensistive
    def validate_name(self, name):
        if adminUtils.doesNameExistsCi(Company_status, name.data):
            raise ValidationError('That Company Status is already registered')


class personRoleForm(FlaskForm):  # Defines the form class to be used for the user registretion
    # Decalarion of the fields for the form and it's propereties
    name = StringField('Name', validators=[DataRequired()])
    description = StringField('Description', validators=[DataRequired()])
    submit = SubmitField('Register Person Role')

    # Queries to be made in order to validate the form : If Person Role exitst  # Case Insensistive
    def validate_name(self, name):
        if adminUtils.doesNameExistsCi(Person_role, name.data):
            raise ValidationError('That Person Role is already registered')


class personCompetenceForm(FlaskForm):  # Defines the form class to be used for the user registretion
    # Decalarion of the fields for the form and it's propereties
    name = StringField('Name', validators=[DataRequired()])
    description = StringField('Description', validators=[DataRequired()])
    submit = SubmitField('Register Person Competence')

    # Queries to be made in order to validate the form : If Person Role exitst  # Case Insensistive
    def validate_name(self, name):
        if adminUtils.doesNameExistsCi(Person_competence, name.data):
            raise ValidationError('That Person Conpetence is already registered')


class noteStatusForm(FlaskForm):  # Defines the form class to be used for the user registretion
    # Decalarion of the fields for the form and it's propereties
    name = StringField('Name', validators=[DataRequired()])
    description = StringField('Description', validators=[DataRequired()])
    submit = SubmitField('Register Note Status')

    # Queries to be made in order to validate the form : If Person Role exitst  # Case Insensistive
    def validate_name(self, name):
        if adminUtils.doesNameExistsCi(Note_status, name.data):
            raise ValidationError('That Note Status is already registered')


class projectStatusForm(FlaskForm):  # Defines the form class to be used for the user registretion
    # Decalarion of the fields for the form and it's propereties
    name = StringField('Name', validators=[DataRequired()])
    description = StringField('Description', validators=[DataRequired()])
    submit = SubmitField('Register Project Status')

    # Queries to be made in order to validate the form : If Person Role exitst  # Case Insensistive
    def validate_name(self, name):
        if adminUtils.doesNameExistsCi(Project_status, name.data):
            raise ValidationError('That Project Status is already registered')


class productStatusForm(FlaskForm):
    # Decalarion of the fields for the form and it's propereties
    name = StringField('Name', validators=[DataRequired()])
    description = StringField('Description', validators=[DataRequired()])
    submit = SubmitField('Register Product Status')

    # Queries to be made in order to validate the form : If Person Role exitst  # Case Insensistive
    def validate_name(self, name):
        if adminUtils.doesNameExistsCi(Product_status, name.data):
            raise ValidationError('That Product Status is already registered')


class productEligibilityForm(FlaskForm):
    # Decalarion of the fields for the form and it's propereties
    name = StringField('Name', validators=[DataRequired()])
    description = StringField('Description', validators=[DataRequired()])
    submit = SubmitField('Register Product Eligibility')

    # Queries to be made in order to validate the form : If Person Role exitst  # Case Insensistive
    def validate_name(self, name):
        if adminUtils.doesNameExistsCi(Product_eligibility, name.data):
            raise ValidationError('That Product Eligibility is already registered')


class productDomainForm(FlaskForm):
    # Decalarion of the fields for the form and it's propereties
    name = StringField('Name', validators=[DataRequired()])
    description = StringField('Description', validators=[DataRequired()])
    submit = SubmitField('Register Product Domain')

    # Queries to be made in order to validate the form : If Person Role exitst  # Case Insensistive
    def validate_name(self, name):
        if adminUtils.doesNameExistsCi(Product_domain, name.data):
            raise ValidationError('That Product domain is already registered')


class productClassificationForm(FlaskForm):
    # Decalarion of the fields for the form and it's propereties
    name = StringField('Name', validators=[DataRequired()])
    description = StringField('Description', validators=[DataRequired()])
    submit = SubmitField('Register Prodcut Classification')

    # Queries to be made in order to validate the form : If Person Role exitst  # Case Insensistive
    def validate_name(self, name):
        if adminUtils.doesNameExistsCi(Product_classification, name.data):
            raise ValidationError('That Product Classification is already registered')


class productCategoryForm(FlaskForm):
    # Decalarion of the fields for the form and it's propereties
    name = StringField('Name', validators=[DataRequired()])
    description = StringField('Description', validators=[DataRequired()])
    submit = SubmitField('Register Product Category')

    # Queries to be made in order to validate the form : If Person Role exitst  # Case Insensistive
    def validate_name(self, name):
        if adminUtils.doesNameExistsCi(Product_category, name.data):
            raise ValidationError('That Product Category is already registered')


class productSubCategoryForm(FlaskForm):
    # Decalarion of the fields for the form and it's propereties
    name = StringField('Name', validators=[DataRequired()])
    description = StringField('Description', validators=[DataRequired()])
    submit = SubmitField('Register Product Sub Category')

    # Queries to be made in order to validate the form : If Person Role exitst  # Case Insensistive
    def validate_name(self, name):
        if adminUtils.doesNameExistsCi(Product_sub_category, name.data):
            raise ValidationError('That Product Sub Category is already registered')
