function model = validateModelSpec(model)
%VALIDATEMODELSPEC - Verify that the 'ModelSpecification' argument is given correctly
%   MODEL = VALIDATEMODELSPEC(MODEL) takes in a model for (M)ANOVA
%   specified as:
%       - A double/single/logical terms matrix
%       - A double/single scalar integer, indicating the maximum depth of
%         interaction terms to include (e.g., 2 means all terms up to and 
%         including two-way interaction terms)
%       - A string/char of a model alias
%       - A string/char of a formula in Wilkinson notation
%
%   It returns the input model spec, converted to double if it was a
%   logical matrix. This function performs basic type validation. Further
%   validation of the model being appropriate for the given data is done
%   elsewhere.

%   Copyright 2022-2023 The MathWorks, Inc.

if islogical(model)
    model = double(model);
end
if isfloat(model)
    % Terms matrix or integer of number of interactions
    validateattributes(model, {'double', 'single'}, {'2d', 'nonempty', 'real', 'nonsparse', 'finite', 'nonnan', '>=', 0, 'integer'}, ...
        mfilename, 'ModelSpecification');
else
    % Model alias or formula in Wilkinson notation. Already converted from
    % string to char at this point
    validateattributes(model, {'char'}, {'scalartext', 'nonempty'}, mfilename, 'ModelSpecification');
end