# 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=['Setup'])
security = HTTPBearer(auto_error=False)
registry = HandlerRegistry()


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

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

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


@router.post(
    '/v1/operations/azure/scripts',
    response_model=V1OperationsAzureScriptsPostResponse,
    tags=['Setup'],
)
async def generate_script(
    credentials: Annotated[HTTPAuthorizationCredentials, Depends(security)],
    action: Action,
    body: ScriptsRequest = None,
) -> V1OperationsAzureScriptsPostResponse:
    """
    Endpoint to generate scripts
    """

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


@router.post(
    '/v1/operations/azure/service-principal',
    response_model=ServicePrincipalSuccess,
    responses={
        '400': {'model': ValidationError},
        '401': {'model': ValidationError},
        '500': {'model': ValidationError},
    },
    tags=['Setup'],
)
async def service_principal(
    credentials: Annotated[HTTPAuthorizationCredentials, Depends(security)],
    action: Action7,
    body: V1OperationsAzureServicePrincipalPostRequest = ...,
) -> Union[ServicePrincipalSuccess, ValidationError]:
    """
    Service Principal validation and storage
    """

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


__all__ = ['SetupHandler', 'registry']
