#!/usr/bin/env python
from peyotl.phylesystem.phylesystem_umbrella import Phylesystem, PhylesystemProxy
from peyotl.api.wrapper import _WSWrapper, APIWrapper
from peyotl.api.study_ref import TreeRef
from peyotl.nexson_syntax import create_content_spec
from peyotl.utility import get_logger
import anyjson
import urllib
import os

_LOG = get_logger(__name__)

_GET_LOCAL, _GET_EXTERNAL, _GET_API = range(3)
_GET_FROM_VALUES = ('local',  # only from local copy of phylesystem
                    'external',  # *DEFAULT* from external URLs
                    'api',)  # from the GET calls of the phylesystem-api
# TRANSFORM only relevant when get_from is "api"
_TRANS_CLIENT, _TRANS_SERVER = range(2)
_TRANSFORM_VALUES = ('client',  # *DEFAULT* transform to the desired output format on the client side
                     'server',)  # request data transformation take place on the server
# REFRESH is only relevant when get_from is "local"
_REFR_NEVER, _REFR_SESSION, _REFR_ALWAYS = range(3)
_REFRESH_VALUES = ('never',  # *DEFAULT* never call "git pull"
                   'session',  # call "git pull" before the first access
                   'always',)  # do a "git pull" before each data access


class _PhylesystemAPIWrapper(_WSWrapper):
    def __init__(self, domain, **kwargs):
        self._prefix = None
        _WSWrapper.__init__(self, domain, **kwargs)
        self.domain = domain
        self._github_oauth_token = None
        self._get_from = kwargs.setdefault('get_from', 'external').lower()
        self._transform = kwargs.setdefault('transform', 'client').lower()
        self._refresh = kwargs.setdefault('refresh', 'never').lower()