<?php

namespace Mtc\Plugins\BlockManager\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Routing\Controller;
use Mtc\Plugins\BlockManager\Models\BlockManagerBlock;
use Mtc\Plugins\BlockManager\Services\BlockShipDiffService;
use Mtc\Plugins\BlockManager\Services\BlockShipService;

class BlockShipController extends Controller
{
    public function __construct(
        private BlockShipService $shipService,
        private BlockShipDiffService $diffService,
    ) {
    }

    public function ship(int $id): JsonResponse
    {
        $block = BlockManagerBlock::findOrFail($id);
        $result = $this->shipService->ship($block);

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

    public function preview(int $id): JsonResponse
    {
        $block = BlockManagerBlock::findOrFail($id);
        $diff = $this->diffService->diff($block);

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