# Path: monasca_api/v2/common/exceptions.py
# class HTTPUnprocessableEntityError(HTTPError):
#     def __init__(self, title, description, **kwargs):
#         HTTPError.__init__(self, '422 Unprocessable Entity', title, description, **kwargs)


from monasca_api.v2.common.exceptions import HTTPUnprocessableEntityError
import re
VALID_ALARM_DEFINITION_SEVERITIES = ["LOW", "MEDIUM", "HIGH", "CRITICAL"]

EMAIL_PATTERN = '^.+@.+$'


def validate_alarm_state(state):
    if state.upper() not in VALID_ALARM_STATES:
        raise HTTPUnprocessableEntityError("Invalid State",
                                           "State {} must be one of {}".format(state.encode('utf8'),
                                                                               VALID_ALARM_STATES))


def validate_alarm_definition_severity(severity):
    if severity.upper() not in VALID_ALARM_DEFINITION_SEVERITIES:
        raise HTTPUnprocessableEntityError(
            "Invalid Severity",
            "Severity {} must be one of {}".format(severity.encode('utf8'),
                                                   VALID_ALARM_DEFINITION_SEVERITIES))


def validate_severity_query(severity_str):
    severities = severity_str.split('|')
    for severity in severities:
        validate_alarm_definition_severity(severity)


def validate_sort_by(sort_by_list, allowed_sort_by):
    for sort_by_field in sort_by_list:
        sort_by_values = sort_by_field.split()
        if len(sort_by_values) > 2:

# Path: monasca_api/v2/common/exceptions.py
# class HTTPUnprocessableEntityError(HTTPError):
#     def __init__(self, title, description, **kwargs):
#         HTTPError.__init__(self, '422 Unprocessable Entity', title, description, **kwargs)


# Path: monasca_api/v2/common/validation.py
from monasca_api.v2.common.exceptions import HTTPUnprocessableEntityError
import re

VALID_ALARM_DEFINITION_SEVERITIES = ["LOW", "MEDIUM", "HIGH", "CRITICAL"]

EMAIL_PATTERN = '^.+@.+$'


def validate_alarm_state(state):
    if state.upper() not in VALID_ALARM_STATES:
        raise HTTPUnprocessableEntityError("Invalid State",
                                           "State {} must be one of {}".format(state.encode('utf8'),
                                                                               VALID_ALARM_STATES))


def validate_alarm_definition_severity(severity):
    if severity.upper() not in VALID_ALARM_DEFINITION_SEVERITIES:
        raise HTTPUnprocessableEntityError(
            "Invalid Severity",
            "Severity {} must be one of {}".format(severity.encode('utf8'),
                                                   VALID_ALARM_DEFINITION_SEVERITIES))


def validate_severity_query(severity_str):
    severities = severity_str.split('|')
    for severity in severities:
        validate_alarm_definition_severity(severity)


def validate_sort_by(sort_by_list, allowed_sort_by):
    for sort_by_field in sort_by_list:
        sort_by_values = sort_by_field.split()
        if len(sort_by_values) > 2:

            raise HTTPUnprocessableEntityError("Unprocessable Entity",