"""Admin catalog endpoints.

Currently exposes a single operation: seed the "Server Hardware" catalog
(4 categories + 35 products) into the existing ``product_categories`` and
``products`` tables. Idempotent — safe to call multiple times.
"""

from __future__ import annotations

import logging
from typing import Any, Dict

from core.database import get_db
from dependencies.auth import get_admin_user
from fastapi import APIRouter, Depends
from schemas.auth import UserResponse
from scripts.seed_server_hardware import seed_server_hardware
from sqlalchemy.ext.asyncio import AsyncSession


logger = logging.getLogger(__name__)

router = APIRouter(prefix="/api/v1/admin/catalog", tags=["admin-catalog"])


@router.post("/seed-server-hardware")
async def seed_server_hardware_endpoint(
    _admin: UserResponse = Depends(get_admin_user),
    db: AsyncSession = Depends(get_db),
) -> Dict[str, Any]:
    """Seed the Server Hardware catalog. Safe to run repeatedly."""
    report = await seed_server_hardware(db)
    return {"ok": True, "report": report}