function T = checkAndPrepareTableForPrediction(this, XTable, caller)
% Check input, then find the required variables by Name and put
% them in the order matching VarSpec.
%

%   Copyright 2016-2022 The MathWorks, Inc.

if isempty(XTable)
    T = table;
    return;
elseif ~istable(XTable)
    bayesoptim.err('PredictArgNotTable', caller);
else
    T = table;
    VarNames = this.PrivOptions.VarSpec.Names;
    for i = 1:numel(VarNames)
        if ~ismember(VarNames{i}, XTable.Properties.VariableNames)
            bayesoptim.err('PredictVarMissing', VarNames{i});
        end
        T.(VarNames{i}) = XTable.(VarNames{i});
    end
    % Apply conditional variable function and canonicalize
    T = applyConditionalVariableFcn(this, T);
    T = canonicalizePoints(this, T);
end
end
