"""Shared FastAPI dependencies."""

from typing import Annotated

from fastapi import Depends, Header, HTTPException, status

from app.core.config import settings


def verify_admin_token(
    x_admin_token: Annotated[str | None, Header(alias="X-Admin-Token")] = None,
) -> None:
    """Verify admin token header. Raises 503 if not configured, 401 if invalid or missing."""
    if not settings.scrape_admin_token:
        raise HTTPException(
            status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
            detail="admin disabled — set SCRAPE_ADMIN_TOKEN",
        )
    if x_admin_token != settings.scrape_admin_token:
        raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="invalid admin token")


AdminTokenAuth = Annotated[None, Depends(verify_admin_token)]
