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


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

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

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


@router.post(
    '/v1/operations/aws/accounts',
    response_model=RegisteredAccountsResponse,
    responses={
        '400': {'model': InvalidAccountsResponse},
        '404': {'model': InvalidAccountsResponse},
    },
    tags=['Account'],
)
async def register_aws_accounts(
    credentials: Annotated[HTTPAuthorizationCredentials, Depends(security)],
    body: AccountRegistration,
) -> Union[RegisteredAccountsResponse, InvalidAccountsResponse]:
    """
    Register AWS accounts with assume role
    """

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


@router.post(
    '/v1/operations/aws/assume_role_template', response_model=bytes, tags=['Account']
)
async def get_assume_role_template(
    credentials: Annotated[HTTPAuthorizationCredentials, Depends(security)],
    body: AssumeRoleTemplateRequest,
) -> bytes:
    """
    Generate Assume Role and OU role CloudFormation templates
    """

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


__all__ = ['AccountHandler', 'registry']
