# Copyright (c) CloudZero - ALL RIGHTS RESERVED - PROPRIETARY AND CONFIDENTIAL
# Unauthorized copying of this file and/or project, via any medium is strictly prohibited.
# Direct all questions to legal@cloudzero.com

from czpowertools.api_configuration import PublicApiConfiguration, WebApiConfiguration
from czpowertools.event_handler.public_api_event_handler import PublicApiGatewayRestResolver
from czpowertools.event_handler.router.public_api_router import PublicApiRouter
from czpowertools.event_handler.router.web_api_router import WebApiRouter
from czpowertools.event_handler.web_api_event_handler import WebApiGatewayRestResolver


class WebApiBuilder:
    """
    Builder for the Web API.
    """

    routers: list[WebApiRouter] = []

    def __init__(self, configuration: WebApiConfiguration | None = None):
        self.configuration = configuration or WebApiConfiguration()

    def add_router(self, router: WebApiRouter) -> 'WebApiBuilder':
        self.routers.append(router)
        return self

    def build(self) -> WebApiGatewayRestResolver:
        app = WebApiGatewayRestResolver(configuration=self.configuration)
        for router in self.routers:
            app.include_router(router, prefix=router.base_route)
        app.enable_swagger(path=self.configuration.swagger_path)
        return app


class PublicApiBuilder:
    """
    Builder for the Public API.
    """

    routers: list[PublicApiRouter] = []

    def __init__(self, configuration: PublicApiConfiguration | None = None):
        self.configuration = configuration or PublicApiConfiguration()

    def add_router(self, router: PublicApiRouter) -> 'PublicApiBuilder':
        self.routers.append(router)
        return self

    def build(self) -> PublicApiGatewayRestResolver:
        app = PublicApiGatewayRestResolver(configuration=self.configuration)
        for router in self.routers:
            app.include_router(router, prefix=router.base_route)
        app.enable_swagger(path=self.configuration.swagger_path)
        return app
