<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\ActivityLog;
use App\Support\OptionRegistry;
use Illuminate\Http\Request;

class RegistryController extends Controller
{
    // GET /registry — effective option sets + UI metadata.
    public function index()
    {
        return response()->json([
            'sets' => OptionRegistry::all(),
            'meta' => OptionRegistry::meta(),
        ]);
    }

    // PUT /registry — save overrides for the editable option sets.
    public function update(Request $request)
    {
        $data = $request->validate([
            'sets' => ['required', 'array'],
        ]);
        $saved = OptionRegistry::save($data['sets']);
        ActivityLog::record('update', 'registry', 'Updated select-option registry');

        return response()->json(['sets' => $saved]);
    }
}
