<?php

declare(strict_types=1);

namespace App\Http\Controllers\Api\V1\Marketplace;

use App\Http\Controllers\Controller;
use App\Models\MarketplaceItem;
use App\Services\Marketplace\MarketplaceItemService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class MarketplaceAdminController extends Controller
{
    public function __construct(private readonly MarketplaceItemService $service) {}

    public function approve(Request $request, string $id): JsonResponse
    {
        $user = $request->user();
        if (! $user || (! $user->hasRole('tenant_admin') && ! $user->hasRole('super_admin'))) {
            abort(403);
        }
        $item = MarketplaceItem::findOrFail($id);
        $item = $this->service->approve($item);
        return response()->json(['data' => $item]);
    }
}
