# Path: mapmyfitness/validators/base.py
# class BaseValidator(object):
#     privacy_options = (PUBLIC, PRIVATE, FRIENDS)
# 
#     def type_or_types_to_str(self, type_or_types):
#         def repr_to_str(repr):
#             return repr.split(" '")[1].split("'>")[0]
#         if isinstance(type_or_types, (list, tuple)):
#             types = []
#             for repr in type_or_types:
#                 types.append(repr_to_str(str(repr)))
#             return ' or '.join(types)
#         else:
#             return repr_to_str(str(type_or_types))
# 
#     def __init__(self, create_obj=None, search_kwargs=None):
#         if create_obj is None and search_kwargs is None:
#             raise ValidatorException('Either create_obj or search_kwargs must be passed when instantiating a validator.')
#         if create_obj is not None:
#             self.create_obj = create_obj
#         else:  # search_kwargs is not None
#             self.search_kwargs = search_kwargs
#         self.errors = []
# 
#         if hasattr(self, 'create_obj'):
#             self.validate_create()
#         else:  # hasattr(self, 'search_kwargs')
#             self.validate_search()
# 
#     def add_error(self, error):
#         if error not in self.errors:
#             self.errors.append(error)
# 
#     @property
#     def valid(self):
#         return len(self.errors) == 0
# 
#     def validate_create(self):
#         """This should be overridden by subclasses of BaseValidator"""
# 
#     def validate_search(self):
#         """This should be overridden by subclasses of BaseValidator"""
# 
#     def __repr__(self):
#         if len(self.errors):
#             return ' '.join(self.errors)


import datetime
from .base import BaseValidator
        from ..api.workout import aggregate_values, time_series_values
        if 'time_series' in obj:
            time_series = obj['time_series']

            # TODO: conditionally use items() Py3, or iteritmes() Py2 here
            for time_series_key, time_series_list in time_series.items():
                if time_series_key in time_series_values:
                    if time_series_key == 'position':
                        positions = time_series['position']
                        for position in positions:
                            is_list = isinstance(position, list)
                            if not is_list or (is_list and len(position) != 2):
                                self.add_error('Workout time_series position must be a 2-list with the first item being of type int or float and the second item being a dict.')
                            else:
                                position_dict = position[1]
                                for lat_or_lng in ('lat', 'lng'):
                                    if lat_or_lng not in position_dict:
                                        self.add_error('Workout time_series position dict must have a {0} key and be of type int or float.'.format(lat_or_lng))
                    else:
                        for item in time_series[time_series_key]:
                            is_list = isinstance(item, list)
                            if not is_list or (is_list and len(item) != 2) or (is_list and len(item) == 2 and (not isinstance(item[0], (int, float)) or not isinstance(item[1], (int, float)))):
                                self.add_error('Workout time_series {0} must be a 2-list with each item being of type int or float.'.format(time_series_key))

    def validate_search(self):
        search_kwargs = self.search_kwargs

        if 'user' not in search_kwargs or ('user' in search_kwargs and not isinstance(search_kwargs['user'], int)):
            self.add_error('Workout user must exist and be of type int.')

        datetime_args = ['updated_before', 'updated_after', 'created_before', 'created_after', 'started_before', 'started_after']

# Path: mapmyfitness/validators/base.py
# class BaseValidator(object):
#     privacy_options = (PUBLIC, PRIVATE, FRIENDS)
# 
#     def type_or_types_to_str(self, type_or_types):
#         def repr_to_str(repr):
#             return repr.split(" '")[1].split("'>")[0]
#         if isinstance(type_or_types, (list, tuple)):
#             types = []
#             for repr in type_or_types:
#                 types.append(repr_to_str(str(repr)))
#             return ' or '.join(types)
#         else:
#             return repr_to_str(str(type_or_types))
# 
#     def __init__(self, create_obj=None, search_kwargs=None):
#         if create_obj is None and search_kwargs is None:
#             raise ValidatorException('Either create_obj or search_kwargs must be passed when instantiating a validator.')
#         if create_obj is not None:
#             self.create_obj = create_obj
#         else:  # search_kwargs is not None
#             self.search_kwargs = search_kwargs
#         self.errors = []
# 
#         if hasattr(self, 'create_obj'):
#             self.validate_create()
#         else:  # hasattr(self, 'search_kwargs')
#             self.validate_search()
# 
#     def add_error(self, error):
#         if error not in self.errors:
#             self.errors.append(error)
# 
#     @property
#     def valid(self):
#         return len(self.errors) == 0
# 
#     def validate_create(self):
#         """This should be overridden by subclasses of BaseValidator"""
# 
#     def validate_search(self):
#         """This should be overridden by subclasses of BaseValidator"""
# 
#     def __repr__(self):
#         if len(self.errors):
#             return ' '.join(self.errors)


# Path: mapmyfitness/validators/workout.py
import datetime
from .base import BaseValidator
        from ..api.workout import aggregate_values, time_series_values

        if 'time_series' in obj:
            time_series = obj['time_series']

            # TODO: conditionally use items() Py3, or iteritmes() Py2 here
            for time_series_key, time_series_list in time_series.items():
                if time_series_key in time_series_values:
                    if time_series_key == 'position':
                        positions = time_series['position']
                        for position in positions:
                            is_list = isinstance(position, list)
                            if not is_list or (is_list and len(position) != 2):
                                self.add_error('Workout time_series position must be a 2-list with the first item being of type int or float and the second item being a dict.')
                            else:
                                position_dict = position[1]
                                for lat_or_lng in ('lat', 'lng'):
                                    if lat_or_lng not in position_dict:
                                        self.add_error('Workout time_series position dict must have a {0} key and be of type int or float.'.format(lat_or_lng))
                    else:
                        for item in time_series[time_series_key]:
                            is_list = isinstance(item, list)
                            if not is_list or (is_list and len(item) != 2) or (is_list and len(item) == 2 and (not isinstance(item[0], (int, float)) or not isinstance(item[1], (int, float)))):
                                self.add_error('Workout time_series {0} must be a 2-list with each item being of type int or float.'.format(time_series_key))

    def validate_search(self):
        search_kwargs = self.search_kwargs

        if 'user' not in search_kwargs or ('user' in search_kwargs and not isinstance(search_kwargs['user'], int)):
            self.add_error('Workout user must exist and be of type int.')

        datetime_args = ['updated_before', 'updated_after', 'created_before', 'created_after', 'started_before', 'started_after']

        for datetime_arg in datetime_args: