function modelinfo = getModelInformation(model,activity, testcomp)
%

%   Copyright 2008-2022 The MathWorks, Inc.

    modelinfo = [];

    if ischar(model)
        try
            modelH = get_param(model,'Handle');
        catch myException %#ok<NASGU>
            modelH = [];
        end
    else
        modelH = model;
    end
    
    analyzedModelH = modelH;
    SubsystemPath = '';          
    ExtractedModel = '';
    ReplacementModel = '';
    ModelRefReplacementModels = {};
    
    HarnessOwnerModel = '';
    
    if strcmp(activity,'datagen')
        if nargin<3
            error(message('Sldv:DataUtils:NoTestComp'));
        end
        designModelH = testcomp.analysisInfo.designModelH;        
        if ~isempty(testcomp.analysisInfo.analyzedSubsystemH)
            SubsystemPath = getfullname(testcomp.analysisInfo.analyzedSubsystemH);            
            if ~strcmp(testcomp.simMode,'DV_SIMMODE_SIL')
                ExtractedModel = get_param(testcomp.analysisInfo.extractedModelH,'FileName');
            end
        end  
        if ~isempty(testcomp.analysisInfo.replacementInfo.replacementModelH)
            ReplacementModel = get_param(testcomp.analysisInfo.replacementInfo.replacementModelH,'FileName');
        end

        if ~isempty(testcomp.analysisInfo.replacementInfo.mdlRefReplacementModelMap)
            mdlRefReplacementModelH = values(testcomp.analysisInfo.replacementInfo.mdlRefReplacementModelMap);
            ModelRefReplacementModels = get_param(mdlRefReplacementModelH,'FileName');
        end
        
        if strcmp(get_param(designModelH, 'isHarness'),'on')
            HarnessOwnerModel = Simulink.harness.internal.getHarnessOwnerBD(designModelH);
        end
        if testcomp.analysisInfo.blockDiagramExtract
           ExtractedModel = get_param(testcomp.analysisInfo.extractedModelH,'FileName');
        end
        
    elseif strcmp(activity,'dataconvert')                
        designModelH = analyzedModelH;        
    else
        error(message('Sldv:DataUtils:getModelInformation:WrongActivity'));
    end         

    modelinfo.Name = get_param(designModelH,'Name');
    modelinfo.Version = get_param(designModelH,'ModelVersion');
    modelinfo.TimeStamp = get_param(designModelH, 'LastModifiedDate');

    % Create a placeholder to store the checksum associated with the design
    % model. We will update this field in Analyzer::generateData. This is
    % because this function is called twice - firstly while caching static
    % SLDV data and secondly after the analysis completes.
    modelinfo.Checksum = '';

    modelinfo.Author = get_param(designModelH,'Creator');

    if ~isempty(SubsystemPath)
        modelinfo.SubsystemPath = SubsystemPath;
    end
    if ~isempty(ExtractedModel)
        modelinfo.ExtractedModel = ExtractedModel;
    end
  
    if ~isempty(ReplacementModel)
        modelinfo.ReplacementModel = ReplacementModel;
    end

    if ~isempty(ModelRefReplacementModels)
        modelinfo.ModelRefReplacementModels = ModelRefReplacementModels;
    end
    
    if ~isempty(HarnessOwnerModel)
        modelinfo.HarnessOwnerModel = HarnessOwnerModel;
    end
end
% LocalWords:  datagen testcomponent dataconvert
