# Path: scrapebot/emulate.py
# class RecipeStepTypeEnum(enum.Enum):
#     navigate = '-> Navigate to the URL as provided in "value"'
# 
#     find_by_id = '| Find an element using its ID as provided in "value"'
#     find_by_name = '| Find an element using its name as provided in "value"'
#     find_by_class = '| Find one or many element(s) using a CSS class name as provided in "value"'
#     find_by_tag = '| Find one or many element(s) using a tag name as provided in "value"'
#     find_by_link = '| Find one or many <a> element(s) by searching for their complete link as provided in "value"'
#     find_by_link_partial = '| Find one or many <a> element(s) by searching for parts of their link as provided in ' \
#                            '"value"'
#     find_by_css = '| Find one or many element(s) using a more sophisticated CSS selector as provided in "value"'
#     find_by_xpath = '| Find one or many element(s) using a more sophisticated XPath selector as provided in "value"'
# 
#     random_select = '| Randomly select one element of the ones that have been identified in the previous step'
# 
#     scroll_to = '| Scroll the page for "value" pixels (or the page bottom, if not specified) with random breaks'
#     pause = '| Wait for value seconds (+/- 25% to introduce some randomness)'
#     click = '-> Click on the element which has been identified in the previous step'
#     write = '. Write "value" onto the element which has been identified in the previous step'
#     write_slowly = '. Write "value" slowly (i.e., character by character, pausing in between, like slow typing) ' \
#                    'onto the the element which has been identified in the previous step'
#     submit = '-> Submit on the element which has been identified in the previous step'
# 
#     get_text = '<- Store the text of the first element which has been identified in the previous step as data'
#     get_texts = '<<- Store all texts of all elements identified in the previous step as data'
#     get_value = '<- Store the value of the first element which has been identified in the previous step as data'
#     get_values = '<<- Store all values of all elements identified in the previous step as data'
#     get_attribute = '<- Store the value of the attribute as provided in "value" of the first element which has been ' \
#                     'identified in the previous step as data'
#     get_attributes = '<<- Store the values of the attributes as provided in "value" of all elements which have been ' \
#                      'identified in the previous step as data'
#     get_pagetitle = '<- Store the page title as data'
#     get_element_count = '<- Store the number of previously found elements as data'
#     get_htmlsource = '<- Store the complete HTML source code (WARNING: huuuge amount of data; handle with great care)'
# 
#     log = '. Simply log "value" into the log file'
#     data = '. Store "value" as data entry'
#     post_all_data = '. Perform a POST request to the given URL (value) with all collected data from the current run ' \
#                     'as simplified "data" array'
#     post_previous_step_data = '. Perform a POST request to the given URL (value) with collected data from the ' \
#                               'previous step as simplified "data" array'
#     execute_js = '. Execute "value" as JavaScript code (store any returned value as data)'
#     go_back = '<- Go back one step in the browser history'
#     go_forward = '-> Go forward one step in the browser history (only available if you went back before)'
#     unset_prior_element = '. Remove any previously retrieved element (which could cause error upon further navigation)'
#     screenshot = '. Take a screenshot of the whole page as PNG file'
#     sometimes_screenshot = '. Only take a screenshot of the whole page in 5% of the runs of this recipe on any instance'
#     element_screenshot = '. Take a screenshot of the element which has been identified in the previous step as PNG file'
# 
#     # @todo?: allow steps to be grouped (through parent steps) and randomly chosen (either one step or random order)
# 
#     @classmethod
#     def choices(cls):
#         return [(choice.name, choice.value) for choice in cls]
# 
#     @classmethod
#     def coerce(cls, item):
#         try:
#             return item.name if isinstance(item, RecipeStepTypeEnum) else item
#         except KeyError:
#             return None


from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, TextAreaField, BooleanField, SelectField, IntegerField
from wtforms.validators import DataRequired, Email
from scrapebot.emulate import RecipeStepTypeEnum


class RecipeForm(FlaskForm):
    name = StringField('Recipe name', validators=[DataRequired()])
    description = TextAreaField('Description')
    interval = IntegerField('Interval [minutes]', validators=[DataRequired()])
    cookies = BooleanField('Store cookies')
    active = BooleanField('Activated', default=True)
    submit = SubmitField('Save')


class RecipeDuplicateForm(FlaskForm):
    amount = IntegerField('Number of copies to create', validators=[DataRequired()], default=1)
    name = StringField('Pattern for newly created recipe\'s names', validators=[DataRequired()])
    description = TextAreaField('Description for all newly created recipes')
    active = BooleanField('Activate all newly created recipes (i.e., let them run)', default=True)
    user_privileges = BooleanField('Also copy user privileges', default=True)
    submit = SubmitField('Go ahead, create those copies (This is irreversible!)')


class RecipeStepForm(FlaskForm):

# Path: scrapebot/emulate.py
# class RecipeStepTypeEnum(enum.Enum):
#     navigate = '-> Navigate to the URL as provided in "value"'
# 
#     find_by_id = '| Find an element using its ID as provided in "value"'
#     find_by_name = '| Find an element using its name as provided in "value"'
#     find_by_class = '| Find one or many element(s) using a CSS class name as provided in "value"'
#     find_by_tag = '| Find one or many element(s) using a tag name as provided in "value"'
#     find_by_link = '| Find one or many <a> element(s) by searching for their complete link as provided in "value"'
#     find_by_link_partial = '| Find one or many <a> element(s) by searching for parts of their link as provided in ' \
#                            '"value"'
#     find_by_css = '| Find one or many element(s) using a more sophisticated CSS selector as provided in "value"'
#     find_by_xpath = '| Find one or many element(s) using a more sophisticated XPath selector as provided in "value"'
# 
#     random_select = '| Randomly select one element of the ones that have been identified in the previous step'
# 
#     scroll_to = '| Scroll the page for "value" pixels (or the page bottom, if not specified) with random breaks'
#     pause = '| Wait for value seconds (+/- 25% to introduce some randomness)'
#     click = '-> Click on the element which has been identified in the previous step'
#     write = '. Write "value" onto the element which has been identified in the previous step'
#     write_slowly = '. Write "value" slowly (i.e., character by character, pausing in between, like slow typing) ' \
#                    'onto the the element which has been identified in the previous step'
#     submit = '-> Submit on the element which has been identified in the previous step'
# 
#     get_text = '<- Store the text of the first element which has been identified in the previous step as data'
#     get_texts = '<<- Store all texts of all elements identified in the previous step as data'
#     get_value = '<- Store the value of the first element which has been identified in the previous step as data'
#     get_values = '<<- Store all values of all elements identified in the previous step as data'
#     get_attribute = '<- Store the value of the attribute as provided in "value" of the first element which has been ' \
#                     'identified in the previous step as data'
#     get_attributes = '<<- Store the values of the attributes as provided in "value" of all elements which have been ' \
#                      'identified in the previous step as data'
#     get_pagetitle = '<- Store the page title as data'
#     get_element_count = '<- Store the number of previously found elements as data'
#     get_htmlsource = '<- Store the complete HTML source code (WARNING: huuuge amount of data; handle with great care)'
# 
#     log = '. Simply log "value" into the log file'
#     data = '. Store "value" as data entry'
#     post_all_data = '. Perform a POST request to the given URL (value) with all collected data from the current run ' \
#                     'as simplified "data" array'
#     post_previous_step_data = '. Perform a POST request to the given URL (value) with collected data from the ' \
#                               'previous step as simplified "data" array'
#     execute_js = '. Execute "value" as JavaScript code (store any returned value as data)'
#     go_back = '<- Go back one step in the browser history'
#     go_forward = '-> Go forward one step in the browser history (only available if you went back before)'
#     unset_prior_element = '. Remove any previously retrieved element (which could cause error upon further navigation)'
#     screenshot = '. Take a screenshot of the whole page as PNG file'
#     sometimes_screenshot = '. Only take a screenshot of the whole page in 5% of the runs of this recipe on any instance'
#     element_screenshot = '. Take a screenshot of the element which has been identified in the previous step as PNG file'
# 
#     # @todo?: allow steps to be grouped (through parent steps) and randomly chosen (either one step or random order)
# 
#     @classmethod
#     def choices(cls):
#         return [(choice.name, choice.value) for choice in cls]
# 
#     @classmethod
#     def coerce(cls, item):
#         try:
#             return item.name if isinstance(item, RecipeStepTypeEnum) else item
#         except KeyError:
#             return None


# Path: web/main/forms.py
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, TextAreaField, BooleanField, SelectField, IntegerField
from wtforms.validators import DataRequired, Email
from scrapebot.emulate import RecipeStepTypeEnum



class RecipeForm(FlaskForm):
    name = StringField('Recipe name', validators=[DataRequired()])
    description = TextAreaField('Description')
    interval = IntegerField('Interval [minutes]', validators=[DataRequired()])
    cookies = BooleanField('Store cookies')
    active = BooleanField('Activated', default=True)
    submit = SubmitField('Save')


class RecipeDuplicateForm(FlaskForm):
    amount = IntegerField('Number of copies to create', validators=[DataRequired()], default=1)
    name = StringField('Pattern for newly created recipe\'s names', validators=[DataRequired()])
    description = TextAreaField('Description for all newly created recipes')
    active = BooleanField('Activate all newly created recipes (i.e., let them run)', default=True)
    user_privileges = BooleanField('Also copy user privileges', default=True)
    submit = SubmitField('Go ahead, create those copies (This is irreversible!)')


class RecipeStepForm(FlaskForm):

    type = SelectField('Type', choices=RecipeStepTypeEnum.choices(), coerce=RecipeStepTypeEnum.coerce)