# generated by fastapi-codegen:
#   filename:  connector
#   timestamp: 2026-01-26T10:59:30+00:00

from __future__ import annotations

from typing import Annotated

from fastapi import APIRouter, Depends, HTTPException
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer

from centra_sdk.utils.gc_handler import GcHandler
from centra_sdk.utils.handler_registry import HandlerRegistry

from ..dependencies import *

router = APIRouter(tags=['Operations'])
security = HTTPBearer(auto_error=False)
registry = HandlerRegistry()


@registry.register()
class OperationsHandler(GcHandler):

    async def get_integration_configuration_options(
        self,
    ) -> InternalConfigMetadata:
        """This method should be implemented by the subclass."""
        raise HTTPException(
            status_code=404,
            detail=f"get_integration_configuration_options not implemented",
        )

    async def get_dynamic_config_option_values(
        self, body: DynamicConfigOptionValuesRequest
    ) -> DynamicConfigOptionValuesResponse:
        """This method should be implemented by the subclass."""
        raise HTTPException(
            status_code=404, detail=f"get_dynamic_config_option_values not implemented"
        )

    async def set_integration_configuration(self, body: InternalConfig) -> None:
        """This method should be implemented by the subclass."""
        raise HTTPException(
            status_code=404, detail=f"set_integration_configuration not implemented"
        )


@router.get(
    '/v1/operations/internal/config_metadata',
    response_model=InternalConfigMetadata,
    tags=['Operations'],
)
async def get_integration_configuration_options(
    credentials: Annotated[HTTPAuthorizationCredentials, Depends(security)],
) -> InternalConfigMetadata:
    """
    Endpoint to retrieve internal configuration options
    """

    token = credentials.credentials if credentials else None
    return await registry.call_handler(
        get_integration_configuration_options.__name__,
        token,
    )


@router.post(
    '/v1/operations/internal/dynamic_config_option_values',
    response_model=DynamicConfigOptionValuesResponse,
    tags=['Operations'],
)
async def get_dynamic_config_option_values(
    credentials: Annotated[HTTPAuthorizationCredentials, Depends(security)],
    body: DynamicConfigOptionValuesRequest,
) -> DynamicConfigOptionValuesResponse:
    """
    Endpoint to retrieve dynamic configuration option values
    """

    token = credentials.credentials if credentials else None
    return await registry.call_handler(
        get_dynamic_config_option_values.__name__, token, body
    )


@router.post(
    '/v1/operations/internal/internal_config', response_model=None, tags=['Operations']
)
async def set_integration_configuration(
    credentials: Annotated[HTTPAuthorizationCredentials, Depends(security)],
    body: InternalConfig,
) -> None:
    """
    Endpoint to set internal services configuration
    """

    token = credentials.credentials if credentials else None
    return await registry.call_handler(
        set_integration_configuration.__name__, token, body
    )


__all__ = ['OperationsHandler', 'registry']
