using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using PowderCoating.Core.Entities;
using PowderCoating.Core.Interfaces;
using PowderCoating.Shared.Constants;
namespace PowderCoating.Web.Controllers;
///
/// Lightweight API endpoints consumed by the client-side item wizard.
/// Intentionally uses CanManageJobs (not CanManageProducts) so that
/// any user who can create quotes or jobs can also save items to the catalog directly
/// from the wizard without needing a separate catalog-management permission.
///
[Authorize(Policy = AppConstants.Policies.CanManageJobs)]
public class ItemWizardController : Controller
{
private readonly IUnitOfWork _unitOfWork;
private readonly ITenantContext _tenantContext;
private readonly ILogger _logger;
public ItemWizardController(IUnitOfWork unitOfWork, ITenantContext tenantContext,
ILogger logger)
{
_unitOfWork = unitOfWork;
_tenantContext = tenantContext;
_logger = logger;
}
///
/// Returns active catalog categories for the current company with their full hierarchy path
/// (e.g. "Automotive > Wheels") so the wizard dropdown can distinguish categories that share
/// the same name but sit under different parents. Paths are built in-memory after a single
/// query — no extra round-trips needed since ParentCategoryId is a scalar field.
///
[HttpGet]
public async Task GetCatalogCategories()
{
var companyId = _tenantContext.GetCurrentCompanyId();
if (companyId == null) return Json(Array.Empty