classdef PrepareAction < fxptui.internal.action.Action
    %PREPAREACTION Action of preparing a model for conversion
    
    %   Copyright 2019 The MathWorks, Inc.
    
    methods(Access = {?fxptui.internal.action.Action, ?WorkflowTestCase})
        
        function executeLocal(this, converter, workflowSetting)
            
            % extract the TopModel information from the DesignSetting
            designSettings = workflowSetting.getSettingValue('DesignSetting');
            topModel = designSettings.TopModel;
            
            % extract the baseline collection settings
            rangeCollectionMode = this.SettingValueGetterStrategy.getSettingValue('RangeCollectionMode', workflowSetting);
            
            % execute to check
            result = converter.performPrepareSystemForConversion(rangeCollectionMode);
            
            % get the DataLayer instance
            dataLayer = fxptds.DataLayerInterface.getInstance();
            
            % get the current Workflow ID
            currentWorkflow = dataLayer.getCurrentWorkflow(topModel);
            currentWorkflowID = currentWorkflow.ID;
            currentWorkflowIntent = currentWorkflow.WorkflowIntent;
            
            % construct a depot unit
            depotUnit = fxptds.internal.workflow.depot.WorkflowDepotUnit;
            depotUnit = depotUnit.setID(currentWorkflowID);
            depotUnit = depotUnit.setIntent(currentWorkflowIntent);
            depotUnit = depotUnit.setResult(result);
            
            % add the depot unit to dataset
            dataLayer.addDepotUnit(topModel, depotUnit);
        end
        
    end
end
