function modelParamStruct = convertCvTestToModelParameters(obj)
% CONVERTCVTESTTOMODELPARAMETERS convert a CvTest object to a structure with
%model parameters

% Copyright 2019 The MathWorks, Inc.
    
    cvTestObj = obj.CvTestSpec;
    modelParamStruct = struct;

    % Return empty structure if 'CvTestSpec' itself is empty
    if isempty(cvTestObj)
        return;
    end
    
    if ~isempty(cvTestObj.rootPath)
        modelParamStruct.CovPath = cvTestObj.rootPath;
    end
    
    parametersMap = obj.getCvTestFieldsToModelParametersMap;
    
    % define the level of structural coverage based on decision, condition
    % and mcdc flags
    if cvTestObj.settings.mcdc
        modelParamStruct.(parametersMap('mcdc')) = 'MCDC';
        modelParamStruct.(parametersMap('mcdcmode')) = char(cvTestObj.options.mcdcMode);
    elseif cvTestObj.settings.condition
        modelParamStruct.(parametersMap('condition')) = 'ConditionDecision';
    elseif cvTestObj.settings.decision
        modelParamStruct.(parametersMap('decision')) = 'Decision';
    else
        modelParamStruct.(parametersMap('decision')) = 'BlockExecution';
    end
    
    % set the Simulink Design Verifier coverage based on designverifier
    % flag
    if cvTestObj.settings.designverifier
        modelParamStruct.(parametersMap('designverifier')) = 'on';
    else
        modelParamStruct.(parametersMap('designverifier')) = 'off';
    end
    
    % set the relational boundary check and the boundaries based on
    % relationalop flag
    if cvTestObj.settings.relationalop
        modelParamStruct.(parametersMap('relationalop')) = 'on';
        modelParamStruct.(parametersMap('covBoundaryRelTol')) = cvTestObj.options.covBoundaryRelTol;
        modelParamStruct.(parametersMap('covBoundaryAbsTol')) = cvTestObj.options.covBoundaryAbsTol;
    else
        modelParamStruct.(parametersMap('relationalop')) = 'off';
    end
    
    % define the model reference coverage settings
    modelParamStruct.(parametersMap('modelRefSettingsEnable')) = cvTestObj.modelRefSettings.enable;
    
    if strcmp(cvTestObj.modelRefSettings.enable, 'filtered')
        modelParamStruct.(parametersMap('excludedModels')) = cvTestObj.modelRefSettings.excludedModels;
    else
        modelParamStruct.(parametersMap('excludedModels')) = '';
    end
    
    if ~strcmp(cvTestObj.modelRefSettings.enable, 'off') && cvTestObj.modelRefSettings.excludeTopModel
        modelParamStruct.(parametersMap('excludeTopModel')) = 'off';    % corresponding parameter is CovIncludeTopModel
    else
        modelParamStruct.(parametersMap('excludeTopModel')) = 'on';
    end
    
    % define coverage settings for external functions
    if cvTestObj.emlSettings.enableExternal
        modelParamStruct.(parametersMap('enableExternal')) = 'on';
    else
        modelParamStruct.(parametersMap('enableExternal')) = 'off';
    end
    
    % define coverage settings for S-functions
    if cvTestObj.sfcnSettings.enableSfcn
        modelParamStruct.(parametersMap('enableSfcn')) = 'on';
    else
        modelParamStruct.(parametersMap('enableSfcn')) = 'off';
    end
    
    % set the coverage filter filename
    modelParamStruct.(parametersMap('filter')) = cvTestObj.filter.fileName;
    
    %%%% additional settings to take care of
    if cvTestObj.settings.tableExec
        modelParamStruct.(parametersMap('tableExec')) = 'on';
    else
        modelParamStruct.(parametersMap('tableExec')) = 'off';
    end
    
    if cvTestObj.settings.sigrange
        modelParamStruct.(parametersMap('sigrange')) = 'on';
    else
        modelParamStruct.(parametersMap('sigrange')) = 'off';
    end
    
    if cvTestObj.settings.sigsize
        modelParamStruct.(parametersMap('sigsize')) = 'on';
    else
        modelParamStruct.(parametersMap('sigsize')) = 'off';
    end

    if cvTestObj.settings.overflowsaturation
        modelParamStruct.(parametersMap('overflowsaturation')) = 'on';
    else
        modelParamStruct.(parametersMap('overflowsaturation')) = 'off';
    end

    if cvTestObj.options.forceBlockReduction
        modelParamStruct.(parametersMap('forceBlockReduction')) = 'on';
    else
        modelParamStruct.(parametersMap('forceBlockReduction')) = 'off';
    end
    
    if cvTestObj.options.useTimeInterval
        modelParamStruct.(parametersMap('useTimeInterval')) = 'on';
        modelParamStruct.(parametersMap('intervalStartTime')) = cvTestObj.options.intervalStartTime;
        modelParamStruct.(parametersMap('intervalStopTime')) = cvTestObj.options.intervalStopTime;
    else
        modelParamStruct.(parametersMap('useTimeInterval')) = 'off';
    end
    
end

