<?php

declare(strict_types=1);

namespace Maestro\Core\Http\Controllers\Superadmin;

use Illuminate\Http\JsonResponse;
use Maestro\Core\Http\Controllers\Controller;
use Maestro\Core\Http\Requests\Superadmin\ResetUserTableStateRequest;
use Maestro\Core\Models\UserTableState;

final class UserTableStateResetController extends Controller
{
    public function __invoke(ResetUserTableStateRequest $request): JsonResponse
    {
        $userId = (int) $request->validated('userId');
        $tableKey = (string) $request->validated('tableKey');

        UserTableState::query()
            ->where('user_id', $userId)
            ->where('table_key', $tableKey)
            ->delete();

        return response()->json(['ok' => true]);
    }
}
