from fastapi import APIRouter, HTTPException

from app.core.mock_state import MODULE_CATALOG
from app.services.tenant_store import get_tenant_store


router = APIRouter()


@router.get("/catalog")
def modules_catalog() -> dict[str, object]:
    return {"items": MODULE_CATALOG}


@router.get("/tenant/{tenant_slug}")
def tenant_modules(tenant_slug: str) -> dict[str, object]:
    context = get_tenant_store().get_context_by_slug(tenant_slug)
    if context is None:
        raise HTTPException(status_code=404, detail="Tenant non trovato")

    return {"tenant": context["tenant"], "tenant_modules": context["tenant_modules"]}
