<?php

namespace App\Http\Controllers\Api\Tenant;

use App\Http\Controllers\Controller;
use App\Services\Addons\EventAddonCatalog;
use Illuminate\Http\JsonResponse;

class EventAddonCatalogController extends Controller
{
    public function __construct(private readonly EventAddonCatalog $catalog) {}

    public function index(): JsonResponse
    {
        $addons = collect($this->catalog->all())
            ->filter(fn (array $addon) => ! empty($addon['price_id']))
            ->map(fn (array $addon, string $key) => array_merge($addon, ['key' => $key]))
            ->values()
            ->all();

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