function options = processOptions(options)
%PROCESSOPTIONS Process solver options
%   Checks unsupported solver options class, process option
%   "FinDiffRelStep", and convert optim.options.SolverOptions to struct.

%   Copyright 2023 The MathWorks, Inc.

optionClass = split(class(options), '.');
solverName = lower(optionClass{end}); % the name the solver it is created for

supportedSolvers = {'fmincon', 'fminunc', 'fseminf', 'fsolve', 'lsqcurvefit', 'lsqnonlin'};

if ~any(strcmpi(solverName, supportedSolvers)) % OPTIONS's solver is not supported
    error(message('optim:checkGradients:UnsupportedSolver', strjoin(supportedSolvers, ', ')));
end

options = prepareOptionsForSolver(options, solverName); % Prepare OPTIONS for finite difference

end
