#XYZZY:EXPERIMENT
print("XYZZY:UNIFY-APP-EXPERIMENT")
from chalice import Chalice
import os
from .app_utils import AppUtilsCore

class AppRoutesInfo:
    def __init__(self):
        self.CHALICE_LOCAL = (os.environ.get("CHALICE_LOCAL") == "1")
        if self.CHALICE_LOCAL:
            self.ROUTE_PREFIX = "/api/"
            self.ROUTE_EMPTY_PREFIX = "/api"
            self.CORS = True
        else:
            self.ROUTE_PREFIX = "/"
            self.ROUTE_EMPTY_PREFIX = "/"
        self.CORS = False
        self.app = Chalice("XYZZY-ROUTE-EXPERIMENT")
        self.app_utils = AppUtilsCore()

app_routes_info = AppRoutesInfo()

@app_routes_info.app.route(app_routes_info.ROUTE_EMPTY_PREFIX + "xyzzy/{environ}", methods=['GET'], cors=app_routes_info.CORS)
def chalice_route_xyzzy(environ):
    print("XYZZY:UNIFIER-ROUTE-EXPERIMENT")
    request = app_routes_info.app.current_request
    request_dict = request.to_dict()
    domain, context = app_routes_info.app_utils.get_domain_and_context(request_dict)
    return app_routes_info.app_utils.react_get_header_info(request=request, environ=environ, domain=domain, context=context)

class XYZZY2:
    print('XYZZY:UNIFY-EXPERIMENT:CLASS-2')
    def __init__(self, app, app_utils_obj):
        XYZZY2.app = app
        XYZZY2.app_utils_obj = app_utils_obj
        print('XYZZY:UNIFY-EXPERIMENT:XYZZY/CTOR-2')

    @staticmethod
    @app.route(ROUTE_PREFIX + 'reactapi/{environ}/xyzzy', methods=["GET"], cors=CORS)
    def react_get_header(environ):
        print(f"XYZZY:UNIFY-EXPERIMENT-2:/reactapi/{environ}/xyzzy")
        request = XYZZY2.app.current_request
        request_dict = request.to_dict()
        domain, context = XYZZY2.app_utils_obj.get_domain_and_context(request_dict)
        return XYZZY2.app_utils_obj.react_get_header_info(request=request, environ=environ, domain=domain, context=context)
