from starlette.applications import Starlette

from starlette_proxy_router.authenfication import check_auth_midlleware
from starlette_proxy_router.parser import Parser
from starlette_proxy_router.routing import create_routes
from starlette_proxy_router.types import PathConfigs


def create_proxy_router(app: Starlette, path_configs: PathConfigs = "config.json") -> None:
    parser = Parser(path_configs)
    endpoints_args = parser.parse_configs()
    check_auth_midlleware(app.user_middleware, endpoints_args)
    proxy_routes = create_routes(endpoints_args)
    app.router.routes.extend(proxy_routes)  # type: ignore
