# Path: restapi/rest_utils.py
# class FeatureCollection(FeatureSetBase):
#     """Class that handles Geo JSON formatted Feature Set, known as a FeatureCollection."""
#     _format = GEOJSON_FORMAT
# 
#     def __init__(self, in_json):
#         """Inits class with JSON as geo feature set.
# 
#         Args:
#             in_json: Input json response from request.
#         """
# 
#         if isinstance(in_json, six.string_types):
#             if not in_json.startswith('{') and os.path.isfile(in_json):
#                 with open(in_json, 'r') as f:
#                     in_json = json.load(f)
#             else:
#                 in_json = json.loads(in_json)
#         if isinstance(in_json, self.__class__):
#             self.json = in_json.json
#         elif isinstance(in_json, dict):
#             self.json = munch.munchify(in_json)
# 
# 
#     def extend(other):
#         """Combines features from another FeatureSet with this one.
# 
#         Args:
#             other: Other FeatureSet to combine with this one.
#         """
# 
#         if not isinstance(other, FeatureCollection):
#             other = FeatureCollection(other)
#         otherCopy = copy.deepcopy(other)
# 
#         # get max oid
#         oidF = getattr(self, OID_FIELD_NAME) if hasattr(self, OID_FIELD_NAME) else OBJECTID
#         nextOID = max([ft.get(oidF, 0) for ft in iter(self)]) + 1
# 
#         if sorted(self.list_fields()) == sorted(other.list_fields()):
#             for ft in otherCopy.features:
#                 if ft.get(oidF) < nextOID:
#                     ft.properties[oidF] = nextOID
#                     nextOID += 1
#             self.features.extend(otherCopy.features)
# 
#     def getEmptyCopy(self):
#         """Gets an empty copy of a feature set."""
#         fsd = munch.Munch()
#         for k,v in six.iteritems(self.json):
#             if k != FEATURES:
#                 fsd[k] = v
#         fsd[FEATURES] = []
#         return FeatureCollection(fsd)
# 
# class FeatureSet(FeatureSetBase):
#     """Class that handles feature sets."""
#     _format = ESRI_JSON_FORMAT
# 
#     def __init__(self, in_json):
#         """Inits Class with input JSON for feature set.
# 
#         Args:
#             in_json: Input json response from request.
# 
#         Raises:
#             ValueError: 'Not a valid Feature Set!'
#         """
# 
#         if isinstance(in_json, six.string_types):
#             if not in_json.startswith('{') and os.path.isfile(in_json):
#                 with open(in_json, 'r') as f:
#                     in_json = json.load(f)
#             else:
#                 in_json = json.loads(in_json)
#         if isinstance(in_json, self.__class__):
#             self.json = in_json.json
#         elif isinstance(in_json, dict):
#             self.json = munch.munchify(in_json)
#         if not all(map(lambda k: k in self.json.keys(), [FIELDS, FEATURES])):
#             # print(self.json.keys())
#             raise ValueError('Not a valid Feature Set!')
# 
#     def extend(self, other):
#         """Combines features from another FeatureSet with this one.
# 
#         Args:
#             other: Other FeatureSet to combine with this one.
#         """
#         if not isinstance(other, FeatureSet):
#             other = FeatureSet(other)
#         otherCopy = copy.deepcopy(other)
# 
#         # get max oid
#         oidF = getattr(self, OID_FIELD_NAME) if hasattr(self, OID_FIELD_NAME) else OBJECTID
#         nextOID = max([ft.get(oidF, 0) for ft in iter(self)]) + 1
# 
#         if sorted(self.list_fields()) == sorted(other.list_fields()):
#             for ft in otherCopy.features:
#                 if ft.get(oidF) < nextOID:
#                     ft.attributes[oidF] = nextOID
#                     nextOID += 1
#             self.features.extend(otherCopy.features)
# 
#     def getEmptyCopy(self):
#         """Gets an empty copy of a feature set."""
#         fsd = munch.Munch()
#         for k,v in six.iteritems(self.json):
#             if k == FIELDS:
#                 fsd[k] = [f for f in self.fields if f and not f.name.lower().startswith('shape')]
#             elif k != FEATURES:
#                 fsd[k] = v
#         fsd[FEATURES] = []
#         return FeatureSet(fsd)


import six
import numbers
from ._strings import *
from .rest_utils import FeatureCollection, FeatureSet
from munch import munchify


def is_arcgis(g):
    """ checks if json geometry is arcgis format

    Args:
        dct (dict): json structure

    Returns:
        bool: returns True if json structure is an arcgis type
    """
    # duck type check for restapi.Geometry
    if hasattr(g, JSON):
        g = getattr(g, JSON)
    if isinstance(g, dict):
        if TYPE in g:
            return g.get(TYPE) in ESRI_GEOMETRY_TYPES
        return any(map(lambda x: g.get(x), ESRI_GEOMETRY_PROPS))
    return False


def is_feature_set(dct):
    """ checks if json structure is a feature set

    Args:
        dct (dict): json structure

    Returns:
        bool: returns True if json structure is a feature set
    """

# Path: restapi/rest_utils.py
# class FeatureCollection(FeatureSetBase):
#     """Class that handles Geo JSON formatted Feature Set, known as a FeatureCollection."""
#     _format = GEOJSON_FORMAT
# 
#     def __init__(self, in_json):
#         """Inits class with JSON as geo feature set.
# 
#         Args:
#             in_json: Input json response from request.
#         """
# 
#         if isinstance(in_json, six.string_types):
#             if not in_json.startswith('{') and os.path.isfile(in_json):
#                 with open(in_json, 'r') as f:
#                     in_json = json.load(f)
#             else:
#                 in_json = json.loads(in_json)
#         if isinstance(in_json, self.__class__):
#             self.json = in_json.json
#         elif isinstance(in_json, dict):
#             self.json = munch.munchify(in_json)
# 
# 
#     def extend(other):
#         """Combines features from another FeatureSet with this one.
# 
#         Args:
#             other: Other FeatureSet to combine with this one.
#         """
# 
#         if not isinstance(other, FeatureCollection):
#             other = FeatureCollection(other)
#         otherCopy = copy.deepcopy(other)
# 
#         # get max oid
#         oidF = getattr(self, OID_FIELD_NAME) if hasattr(self, OID_FIELD_NAME) else OBJECTID
#         nextOID = max([ft.get(oidF, 0) for ft in iter(self)]) + 1
# 
#         if sorted(self.list_fields()) == sorted(other.list_fields()):
#             for ft in otherCopy.features:
#                 if ft.get(oidF) < nextOID:
#                     ft.properties[oidF] = nextOID
#                     nextOID += 1
#             self.features.extend(otherCopy.features)
# 
#     def getEmptyCopy(self):
#         """Gets an empty copy of a feature set."""
#         fsd = munch.Munch()
#         for k,v in six.iteritems(self.json):
#             if k != FEATURES:
#                 fsd[k] = v
#         fsd[FEATURES] = []
#         return FeatureCollection(fsd)
# 
# class FeatureSet(FeatureSetBase):
#     """Class that handles feature sets."""
#     _format = ESRI_JSON_FORMAT
# 
#     def __init__(self, in_json):
#         """Inits Class with input JSON for feature set.
# 
#         Args:
#             in_json: Input json response from request.
# 
#         Raises:
#             ValueError: 'Not a valid Feature Set!'
#         """
# 
#         if isinstance(in_json, six.string_types):
#             if not in_json.startswith('{') and os.path.isfile(in_json):
#                 with open(in_json, 'r') as f:
#                     in_json = json.load(f)
#             else:
#                 in_json = json.loads(in_json)
#         if isinstance(in_json, self.__class__):
#             self.json = in_json.json
#         elif isinstance(in_json, dict):
#             self.json = munch.munchify(in_json)
#         if not all(map(lambda k: k in self.json.keys(), [FIELDS, FEATURES])):
#             # print(self.json.keys())
#             raise ValueError('Not a valid Feature Set!')
# 
#     def extend(self, other):
#         """Combines features from another FeatureSet with this one.
# 
#         Args:
#             other: Other FeatureSet to combine with this one.
#         """
#         if not isinstance(other, FeatureSet):
#             other = FeatureSet(other)
#         otherCopy = copy.deepcopy(other)
# 
#         # get max oid
#         oidF = getattr(self, OID_FIELD_NAME) if hasattr(self, OID_FIELD_NAME) else OBJECTID
#         nextOID = max([ft.get(oidF, 0) for ft in iter(self)]) + 1
# 
#         if sorted(self.list_fields()) == sorted(other.list_fields()):
#             for ft in otherCopy.features:
#                 if ft.get(oidF) < nextOID:
#                     ft.attributes[oidF] = nextOID
#                     nextOID += 1
#             self.features.extend(otherCopy.features)
# 
#     def getEmptyCopy(self):
#         """Gets an empty copy of a feature set."""
#         fsd = munch.Munch()
#         for k,v in six.iteritems(self.json):
#             if k == FIELDS:
#                 fsd[k] = [f for f in self.fields if f and not f.name.lower().startswith('shape')]
#             elif k != FEATURES:
#                 fsd[k] = v
#         fsd[FEATURES] = []
#         return FeatureSet(fsd)


# Path: restapi/conversion.py
import six
import numbers
from ._strings import *
from .rest_utils import FeatureCollection, FeatureSet
from munch import munchify



def is_arcgis(g):
    """ checks if json geometry is arcgis format

    Args:
        dct (dict): json structure

    Returns:
        bool: returns True if json structure is an arcgis type
    """
    # duck type check for restapi.Geometry
    if hasattr(g, JSON):
        g = getattr(g, JSON)
    if isinstance(g, dict):
        if TYPE in g:
            return g.get(TYPE) in ESRI_GEOMETRY_TYPES
        return any(map(lambda x: g.get(x), ESRI_GEOMETRY_PROPS))
    return False


def is_feature_set(dct):
    """ checks if json structure is a feature set

    Args:
        dct (dict): json structure

    Returns:
        bool: returns True if json structure is a feature set
    """

    if isinstance(dct, FeatureSet):