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


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

    async def set_enforcement_policy_inventory(
        self, action: Optional[Action] = 'set', body: EnforcementPolicyInventory = ...
    ) -> None:
        """This method should be implemented by the subclass."""
        raise HTTPException(
            status_code=404, detail=f"set_enforcement_policy_inventory not implemented"
        )

    async def set_enforcement_policy(
        self, action: Optional[Action] = 'set', body: EnforcementPolicy = ...
    ) -> None:
        """This method should be implemented by the subclass."""
        raise HTTPException(
            status_code=404, detail=f"set_enforcement_policy not implemented"
        )


@router.post('/v1/consumer/inventory', response_model=None, tags=['Enforcement'])
async def set_enforcement_policy_inventory(
    credentials: Annotated[HTTPAuthorizationCredentials, Depends(security)],
    action: Optional[Action] = 'set',
    body: EnforcementPolicyInventory = ...,
) -> None:
    """
    Set enforcement policy inventory
    """

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


@router.post('/v1/consumer/policy', response_model=None, tags=['Enforcement'])
async def set_enforcement_policy(
    credentials: Annotated[HTTPAuthorizationCredentials, Depends(security)],
    action: Optional[Action] = 'set',
    body: EnforcementPolicy = ...,
) -> None:
    """
    Set enforcement policy
    """

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


__all__ = ['EnforcementHandler', 'registry']
