<?php

namespace Mtc\Plugins\BlockManager\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Routing\Controller;
use Mtc\Plugins\BlockManager\Models\BlockManagerVariantDraft;
use Mtc\Plugins\BlockManager\Services\VariantPublishService;

/**
 * Designer publish endpoint — materialises a variant draft into the on-disk
 * element catalogue. The Designer's analogue of Composer's ship pipeline.
 */
class VariantPublishController extends Controller
{
    public function __construct(private VariantPublishService $publishService)
    {
    }

    public function publish(int $id): JsonResponse
    {
        $draft = BlockManagerVariantDraft::findOrFail($id);
        $result = $this->publishService->publish($draft);

        return response()->json(['data' => $result]);
    }
}
