<?php

namespace App\Http\Controllers\Concerns;

use Illuminate\Http\JsonResponse;

trait DestroysCatalogItem
{
    protected function destroyCatalogItem(?string $blockReason, callable $delete): JsonResponse
    {
        if ($blockReason !== null) {
            return response()->json([
                'message' => $blockReason,
                'meta' => null,
                'errors' => null,
            ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY);
        }

        $delete();

        return response()->json([
            'message' => 'Eliminado correctamente.',
            'data' => ['deleted' => true],
            'meta' => null,
            'errors' => null,
        ], JsonResponse::HTTP_OK);
    }
}
