from fastapi import HTTPException, Security
from fastapi.security import APIKeyHeader

from app.config import settings

internal_api_key_header = APIKeyHeader(name="x-internal-api-key", auto_error=False)


async def require_internal_api_key(x_internal_api_key: str | None = Security(internal_api_key_header)) -> None:
    if not x_internal_api_key or x_internal_api_key != settings.soc_integrator_internal_key:
        raise HTTPException(status_code=401, detail="Invalid or missing internal API key")
