function [parameters, variants] = testCaseParametersAndVariants(tc)
%

%   Copyright 2008-2020 The MathWorks, Inc.
    parameters = {};
    variants = {};
    [param_count, variant_count] = getParameterAndVariantCount(tc);

    if variant_count > 0
        variants = {...
            getString(message('Sldv:RptGen:VariantColName')),...
            getString(message('Sldv:RptGen:Value'))...
            };
    end
    
    if param_count > 0
        parameters = {...
            getString(message('Sldv:RptGen:ParameterColName')),...
            getString(message('Sldv:RptGen:Value'))...
            };
    end

    for i=1:length(tc.paramValues)
        if isequal(tc.paramValues(i).type, 'Variant')
            if tc.paramValues(i).noEffect
                valstr = '-';
            else
                valstr = sldvshareprivate('util_num2str', tc.paramValues(i).value);
            end
            
            variants = [ variants; { tc.paramValues(i).name valstr} ]; %#ok<AGROW>
            continue;
        end

        if tc.paramValues(i).noEffect
            valstr = '-';
            parameters = [ parameters; { tc.paramValues(i).name valstr} ]; %#ok<AGROW>
            continue;
        end

        if ~slavteng('feature','BusParameterTuning') || ~isstruct(tc.paramValues(i).value)
            % If the parameter is a non struct/ non Bus value
            valstr = sldvshareprivate('util_num2str', tc.paramValues(i).value);
            parameters = [ parameters; { tc.paramValues(i).name valstr} ]; %#ok<AGROW>
        else
            % If parameter is a struct/Bus type
            parameters = createParamTable(parameters, tc.paramValues(i).name, tc.paramValues(i).value);
        end
    end
end

function parameters = createParamTable(parameters, paramName, paramValue)
    % if the paramValue is a struct, this function prints each leaf of the
    % struct/Bus parameter as rows in a parameter table
    if ~isstruct(paramValue)
        % Leafs - print to pdesc
        valstr = sldvshareprivate('util_num2str', paramValue);
            parameters = [ parameters; { paramName valstr} ];
    else
        % Parameter is not a leaf
        % So, we recccursively look under each field of the struct value
        % untill we find a leaf
        paramFields = fieldnames(paramValue);
        for idx = 1:length(paramFields)
            fieldName = [paramName, '.', paramFields{idx}];
            parameters = createParamTable(parameters, fieldName, paramValue.(paramFields{idx}));
        end
    end
end

function [param_count, variant_count] = getParameterAndVariantCount(tc)
    param_count = 0;
    variant_count = 0;
    for i=1:length(tc.paramValues)
        if isequal(tc.paramValues(i).type, 'Variant')
            variant_count = variant_count + 1;
        else
            param_count = param_count + 1;
        end
    end
end