# 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/gls_fr/rest/constants.py
# SERVICE_FDS = "flexDeliveryService"
# 
# Path: roulier/carriers/gls_fr/rest/constants.py
# SERVICE_SHD = "shopdeliveryservice"
# 
# Path: roulier/carriers/gls_fr/rest/constants.py
# SERVICE_SRS = "shopreturnservice"


from jinja2 import Environment, PackageLoader
from roulier.codec import Encoder
from roulier.exception import InvalidApiInput
from .constants import SERVICE_FDS
from .constants import SERVICE_SHD
from .constants import SERVICE_SRS
import logging
        )
        for p in data["parcels"]:
            parcel = {"weight": "%.2f" % p["weight"]}
            refs = []
            if p.get("reference"):
                refs.append(p["reference"])
            if p.get("reference2"):
                refs.append(p["reference2"])
            if refs:
                parcel["references"] = refs
            if p.get("comment"):
                parcel["comment"] = p["comment"]
            if "services" in p:
                services = []
                for subdata in p["services"]:
                    service = self._set_service(subdata, body)
                    if service:
                        services.append(service)
                if global_sevice:
                    services.append(global_sevice)
                if services:
                    parcel["services"] = services
            parcels.append(parcel)
        return parcels

    def _set_service(self, subdata, body):
        service_name = subdata.get("product")
        if service_name not in (SERVICE_FDS, SERVICE_SHD, SERVICE_SRS):
            return  # service must only be included fot those three ones
        service = {"name": service_name}

# 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/gls_fr/rest/constants.py
# SERVICE_FDS = "flexDeliveryService"
# 
# Path: roulier/carriers/gls_fr/rest/constants.py
# SERVICE_SHD = "shopdeliveryservice"
# 
# Path: roulier/carriers/gls_fr/rest/constants.py
# SERVICE_SRS = "shopreturnservice"


# Path: roulier/carriers/gls_fr/rest/encoder.py
from jinja2 import Environment, PackageLoader
from roulier.codec import Encoder
from roulier.exception import InvalidApiInput
from .constants import SERVICE_FDS
from .constants import SERVICE_SHD
from .constants import SERVICE_SRS
import logging

        )
        for p in data["parcels"]:
            parcel = {"weight": "%.2f" % p["weight"]}
            refs = []
            if p.get("reference"):
                refs.append(p["reference"])
            if p.get("reference2"):
                refs.append(p["reference2"])
            if refs:
                parcel["references"] = refs
            if p.get("comment"):
                parcel["comment"] = p["comment"]
            if "services" in p:
                services = []
                for subdata in p["services"]:
                    service = self._set_service(subdata, body)
                    if service:
                        services.append(service)
                if global_sevice:
                    services.append(global_sevice)
                if services:
                    parcel["services"] = services
            parcels.append(parcel)
        return parcels

    def _set_service(self, subdata, body):
        service_name = subdata.get("product")
        if service_name not in (SERVICE_FDS, SERVICE_SHD, SERVICE_SRS):
            return  # service must only be included fot those three ones
        service = {"name": service_name}

        if service_name == SERVICE_SHD: