# Path: roulier/codec.py
# class Encoder(ABC):
#     def __init__(self, config_object):
#         self.config = config_object
# 
#     def _extra_input_data_processing(self, input_payload, data):
#         return data
# 
#     @abstractmethod
#     def transform_input_to_carrier_webservice(self, data):
#         pass
# 
#     def encode(self, input_payload):
#         """Transform input from external app to compatible input for carrier webservice."""
#         validator = self.config.api(self.config)
#         if not validator.validate(input_payload):
#             _logger.warning("Laposte api call exception:")
#             raise InvalidApiInput(
#                 {"api_call_exception": validator.errors(input_payload)}
#             )
#         # Set isTest in config if it is the case so the system choose the test url
#         # if any
#         if input_payload.get("auth", {}).get("isTest"):
#             self.config.is_test = True
#         data = validator.normalize(input_payload)
#         data = self._extra_input_data_processing(input_payload, data)
#         return self.transform_input_to_carrier_webservice(data)
# 
# Path: roulier/exception.py
# class InvalidApiInput(Exception):
#     """Bad input.
# 
#     Use this class in your application to manage
#     exception with api call
#     """
# 
# Path: roulier/carriers/geodis/geodis_common_ws.py
# GEODIS_INFOS = {
#     "demandeImpressionEtiquette": {
#         "xmlns": "http://impression.service.web.etiquette.geodis.com",
#         "endpoint": "http://espace.geodis.com/geolabel/services/ImpressionEtiquette",  # nopep8
#         "endpoint_test": "http://espace.recette.geodis.com/geolabel/services/ImpressionEtiquette",  # nopep8
#         "api": GeodisApiWs,
#     },
#     "findLocalite": {
#         "xmlns": "http://localite.service.web.etiquette.geodis.com",
#         "endpoint": "http://espace.geodis.com/geolabel/services/RechercherLocalite",  # nopep8
#         "endpoint_test": "http://espace.recette.geodis.com/geolabel/services/RechercherLocalite",  # nopep8
#         "api": GeodisApiFindLocaliteWs,
#     },
#     "trackingList": {
#         "endpoint": "https://espace-client.geodis.com/services",
#         "service": "api/zoomclient/recherche-envois",
#         "api": GeodisApiTrackingList,
#     },
#     "tracking": {
#         "endpoint": "https://espace-client.geodis.com/services",
#         "service": "api/zoomclient/recherche-envoi",
#         "api": GeodisApiTracking,
#     },
# }


from jinja2 import Environment, PackageLoader
from roulier.codec import Encoder
from roulier.exception import InvalidApiInput
from .geodis_common_ws import GEODIS_INFOS
"""Transform input to geodis compatible xml."""


GEODIS_ACTIONS = GEODIS_INFOS.keys()


class GeodisEncoderWs(Encoder):
    """Transform input to geodis compatible xml."""

    def get_api(self, action):
        """Get Api object based on action.

        raise if action is not known"""
        if not (action in GEODIS_ACTIONS):
            raise InvalidApiInput(
                "action %s not in %s" % (action, ", ".join(GEODIS_INFOS))
            )

        return GEODIS_INFOS[action]["api"]()

    def encode(self, api_input, action):
        """Transform input to geodis compatible xml."""
        api = self.get_api(action)
        if not api.validate(api_input):

# Path: roulier/codec.py
# class Encoder(ABC):
#     def __init__(self, config_object):
#         self.config = config_object
# 
#     def _extra_input_data_processing(self, input_payload, data):
#         return data
# 
#     @abstractmethod
#     def transform_input_to_carrier_webservice(self, data):
#         pass
# 
#     def encode(self, input_payload):
#         """Transform input from external app to compatible input for carrier webservice."""
#         validator = self.config.api(self.config)
#         if not validator.validate(input_payload):
#             _logger.warning("Laposte api call exception:")
#             raise InvalidApiInput(
#                 {"api_call_exception": validator.errors(input_payload)}
#             )
#         # Set isTest in config if it is the case so the system choose the test url
#         # if any
#         if input_payload.get("auth", {}).get("isTest"):
#             self.config.is_test = True
#         data = validator.normalize(input_payload)
#         data = self._extra_input_data_processing(input_payload, data)
#         return self.transform_input_to_carrier_webservice(data)
# 
# Path: roulier/exception.py
# class InvalidApiInput(Exception):
#     """Bad input.
# 
#     Use this class in your application to manage
#     exception with api call
#     """
# 
# Path: roulier/carriers/geodis/geodis_common_ws.py
# GEODIS_INFOS = {
#     "demandeImpressionEtiquette": {
#         "xmlns": "http://impression.service.web.etiquette.geodis.com",
#         "endpoint": "http://espace.geodis.com/geolabel/services/ImpressionEtiquette",  # nopep8
#         "endpoint_test": "http://espace.recette.geodis.com/geolabel/services/ImpressionEtiquette",  # nopep8
#         "api": GeodisApiWs,
#     },
#     "findLocalite": {
#         "xmlns": "http://localite.service.web.etiquette.geodis.com",
#         "endpoint": "http://espace.geodis.com/geolabel/services/RechercherLocalite",  # nopep8
#         "endpoint_test": "http://espace.recette.geodis.com/geolabel/services/RechercherLocalite",  # nopep8
#         "api": GeodisApiFindLocaliteWs,
#     },
#     "trackingList": {
#         "endpoint": "https://espace-client.geodis.com/services",
#         "service": "api/zoomclient/recherche-envois",
#         "api": GeodisApiTrackingList,
#     },
#     "tracking": {
#         "endpoint": "https://espace-client.geodis.com/services",
#         "service": "api/zoomclient/recherche-envoi",
#         "api": GeodisApiTracking,
#     },
# }


# Path: roulier/carriers/geodis/geodis_encoder_ws.py
from jinja2 import Environment, PackageLoader
from roulier.codec import Encoder
from roulier.exception import InvalidApiInput
from .geodis_common_ws import GEODIS_INFOS

"""Transform input to geodis compatible xml."""


GEODIS_ACTIONS = GEODIS_INFOS.keys()


class GeodisEncoderWs(Encoder):
    """Transform input to geodis compatible xml."""

    def get_api(self, action):
        """Get Api object based on action.

        raise if action is not known"""
        if not (action in GEODIS_ACTIONS):
            raise InvalidApiInput(
                "action %s not in %s" % (action, ", ".join(GEODIS_INFOS))
            )

        return GEODIS_INFOS[action]["api"]()

    def encode(self, api_input, action):
        """Transform input to geodis compatible xml."""
        api = self.get_api(action)
        if not api.validate(api_input):

            raise InvalidApiInput("Input error : %s" % api.errors(api_input))