# 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 aws_lambda_powertools.event_handler.router import APIGatewayRouter


class PublicApiRouter(APIGatewayRouter):
    """
    CloudZero Public API router for handling public API routes.

    Extends AWS PowerTools APIGatewayRouter with CloudZero-specific functionality
    for public API endpoints including base route management and organization
    context access.
    """

    _base_route: str

    def __init__(self, base_route: str = ''):
        """
        Initialize the Public API router.

        Args:
            base_route: Base route path for all routes in this router.
                       Will be prefixed with '/' if it doesn't start with one.
        """
        super().__init__()
        self._base_route = f'/{base_route}' if base_route and not base_route.startswith('/') else base_route

    @property
    def base_route(self) -> str:
        """
        Get the base route path for this router.

        Returns:
            str: The base route path that will be prefixed to all routes in this router
        """
        return self._base_route

    @property
    def cz_organization_id(self) -> str:
        """
        Get the CloudZero organization ID from the request context.

        This property retrieves the organization ID that was set by the
        ApiKeyAuthorizationContextMiddleware during request processing.

        Returns:
            str: The CloudZero organization ID for the current request
        """
        return str(self.context.get('cz_organization_id'))
