"""Exposes all of the resource endpoints mounted in Flask-Blueprint style.

Uses flask-restx namespaces to mount individual api endpoints into the service.
"""

from flask_jwt_oidc import AuthError
from flask_restx import Api

from .checkpoint import API as CHECKPOINT_API
from .sentiment_analysis import API as SENTIMENT_API

AUTHORIZATIONS = {"apikey": {"type": "apiKey", "in": "header", "name": "Authorization"}}

data_analysis_api = Api(
    version="1.0",
    title="Sentiment-API",
    description="API endpoint for sentiment analysis component for formsflow.ai.",
    security=["apikey"],
    authorizations=AUTHORIZATIONS,
)


@data_analysis_api.errorhandler(AuthError)
def handle_auth_error(error: AuthError):
    """Handle Business exception."""
    return (
        {"message": "Access Denied"},
        error.status_code,
        {"Access-Control-Allow-Origin": "*"},
    )


data_analysis_api.add_namespace(CHECKPOINT_API, path="/checkpoint")
data_analysis_api.add_namespace(SENTIMENT_API, path="/sentiment")
