# generated by fastapi-codegen:
#   filename:  connector
#   timestamp: 2025-12-16T15:57:14+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=['Control'])
security = HTTPBearer(auto_error=False)
registry = HandlerRegistry()


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

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


@router.post(
    '/version/version-handshake',
    response_model=VersionHandshakeData,
    responses={'401': {'model': UnauthorizedError}},
    tags=['Control'],
)
async def version_handshake(
    credentials: Annotated[HTTPAuthorizationCredentials, Depends(security)],
    body: VersionHandshakeData,
) -> Union[VersionHandshakeData, UnauthorizedError]:
    """
    Perform version handshake
    """

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


__all__ = ['ControlHandler', 'registry']
