# Path: ipuz/exceptions.py
# class IPUZException(Exception):
#     pass
# 
# Path: ipuz/structures/common.py
# def validate_dimensions(field_name, field_data):
#     if not isinstance(field_data, dict):
#         raise IPUZException("Invalid {} value found".format(field_name))
#     for key, value in field_data.items():
#         if key not in ("width", "height"):
#             raise IPUZException("Invalid {} value found".format(field_name))
#     for key in ["width", "height"]:
#         if key not in field_data:
#             raise IPUZException(
#                 "Mandatory field {} of dimensions is missing".format(key)
#             )
#         if type(field_data[key]) is not int:
#             raise IPUZException(
#                 "Invalid {} value in dimensions field found".format(key)
#             )
#         if field_data[key] < 1:
#             raise IPUZException(
#                 "Field {} of dimensions is less than one".format(key)
#             )
# 
# Path: ipuz/structures/crosswordvalue.py
# def validate_crosswordvalues(field_name, field_data):
#     validate_list_of_lists(
#         field_name, field_data, "CrosswordValue", validate_crosswordvalue
#     )
# 
# Path: ipuz/structures/groupspec.py
# def validate_groupspec_dict(field_name, field_data):
#     if not isinstance(field_data, dict):
#         raise IPUZException("Invalid {} value found".format(field_name))
#     for key, value in field_data.items():
#         validate_string(field_name, key)
#         if not key:
#             raise IPUZException("Invalid {} value found".format(field_name))
#         if not validate_groupspec(value):
#             raise IPUZException("Invalid {} value found".format(field_name))
# 
# Path: ipuz/validators.py
# def validate_bool(field_name, field_data):
#     if not isinstance(field_data, bool):
#         raise IPUZException("Invalid {} value found".format(field_name))
# 
# def validate_dict_of_strings(field_name, field_data):
#     if not isinstance(field_data, dict):
#         raise IPUZException("Invalid {} value found".format(field_name))
#     for key, value in field_data.items():
#         validate_string(field_name, key)
#         validate_string(field_name, value)
# 
# def validate_elements(field_name, field_data, elements):
#     if field_data not in elements:
#         raise IPUZException("Invalid {} value found".format(field_name))
# 
# def validate_list_of_strings(field_name, field_data):
#     if not isinstance(field_data, list):
#         raise IPUZException("Invalid {} value found".format(field_name))
#     for element in field_data:
#         validate_string(field_name, field_data)
# 
# def validate_non_negative_int(field_name, field_data):
#     validate_int(field_name, field_data)
#     if field_data < 0:
#         raise IPUZException("Invalid {} value found".format(field_name))


from ipuz.exceptions import IPUZException
from ipuz.structures import (
    validate_crosswordvalues,
    validate_dimensions,
    validate_groupspec_dict,
)
from ipuz.validators import (
    validate_bool,
    validate_dict_of_strings,
    validate_elements,
    validate_list_of_strings,
    validate_non_negative_int,
)


def validate_dictionary(field_name, field_data):
    if field_data is True or not isinstance(field_data, str):
        raise IPUZException("Invalid {} value found".format(field_name))


def validate_solution(field_name, field_data):
    if (not isinstance(field_data, (dict, list)) and
            not isinstance(field_data, str)):
        raise IPUZException("Invalid {} value found".format(field_name))
    if isinstance(field_data, list):
        validate_list_of_strings(field_name, field_data)
    if isinstance(field_data, dict):
        validate_groupspec_dict(field_name, field_data)


IPUZ_WORDSEARCH_VALIDATORS = {
    "dimensions": validate_dimensions,
    "puzzle": validate_crosswordvalues,
    "solution": validate_solution,
    "dictionary": validate_dictionary,

# Path: ipuz/exceptions.py
# class IPUZException(Exception):
#     pass
# 
# Path: ipuz/structures/common.py
# def validate_dimensions(field_name, field_data):
#     if not isinstance(field_data, dict):
#         raise IPUZException("Invalid {} value found".format(field_name))
#     for key, value in field_data.items():
#         if key not in ("width", "height"):
#             raise IPUZException("Invalid {} value found".format(field_name))
#     for key in ["width", "height"]:
#         if key not in field_data:
#             raise IPUZException(
#                 "Mandatory field {} of dimensions is missing".format(key)
#             )
#         if type(field_data[key]) is not int:
#             raise IPUZException(
#                 "Invalid {} value in dimensions field found".format(key)
#             )
#         if field_data[key] < 1:
#             raise IPUZException(
#                 "Field {} of dimensions is less than one".format(key)
#             )
# 
# Path: ipuz/structures/crosswordvalue.py
# def validate_crosswordvalues(field_name, field_data):
#     validate_list_of_lists(
#         field_name, field_data, "CrosswordValue", validate_crosswordvalue
#     )
# 
# Path: ipuz/structures/groupspec.py
# def validate_groupspec_dict(field_name, field_data):
#     if not isinstance(field_data, dict):
#         raise IPUZException("Invalid {} value found".format(field_name))
#     for key, value in field_data.items():
#         validate_string(field_name, key)
#         if not key:
#             raise IPUZException("Invalid {} value found".format(field_name))
#         if not validate_groupspec(value):
#             raise IPUZException("Invalid {} value found".format(field_name))
# 
# Path: ipuz/validators.py
# def validate_bool(field_name, field_data):
#     if not isinstance(field_data, bool):
#         raise IPUZException("Invalid {} value found".format(field_name))
# 
# def validate_dict_of_strings(field_name, field_data):
#     if not isinstance(field_data, dict):
#         raise IPUZException("Invalid {} value found".format(field_name))
#     for key, value in field_data.items():
#         validate_string(field_name, key)
#         validate_string(field_name, value)
# 
# def validate_elements(field_name, field_data, elements):
#     if field_data not in elements:
#         raise IPUZException("Invalid {} value found".format(field_name))
# 
# def validate_list_of_strings(field_name, field_data):
#     if not isinstance(field_data, list):
#         raise IPUZException("Invalid {} value found".format(field_name))
#     for element in field_data:
#         validate_string(field_name, field_data)
# 
# def validate_non_negative_int(field_name, field_data):
#     validate_int(field_name, field_data)
#     if field_data < 0:
#         raise IPUZException("Invalid {} value found".format(field_name))


# Path: ipuz/puzzlekinds/wordsearch.py
from ipuz.exceptions import IPUZException
from ipuz.structures import (
    validate_crosswordvalues,
    validate_dimensions,
    validate_groupspec_dict,
)
from ipuz.validators import (
    validate_bool,
    validate_dict_of_strings,
    validate_elements,
    validate_list_of_strings,
    validate_non_negative_int,
)



def validate_dictionary(field_name, field_data):
    if field_data is True or not isinstance(field_data, str):
        raise IPUZException("Invalid {} value found".format(field_name))


def validate_solution(field_name, field_data):
    if (not isinstance(field_data, (dict, list)) and
            not isinstance(field_data, str)):
        raise IPUZException("Invalid {} value found".format(field_name))
    if isinstance(field_data, list):
        validate_list_of_strings(field_name, field_data)
    if isinstance(field_data, dict):
        validate_groupspec_dict(field_name, field_data)


IPUZ_WORDSEARCH_VALIDATORS = {
    "dimensions": validate_dimensions,
    "puzzle": validate_crosswordvalues,
    "solution": validate_solution,
    "dictionary": validate_dictionary,

    "saved": validate_list_of_strings,