classdef WorkflowEngineFactory < handle
    % WORKFLOWENGINEFACTORY Different workflow steps need a different
    % engine to perform their task
    %
    % SEE ALSO: fxptui.internal.ActionFactory,
    % fxptui.internal.action.Action
    
    %   Copyright 2019-2022 The MathWorks, Inc.
    
    methods(Static)
        
        function engine = getWorkflowEngine(keyword, workflowSetting)
            
            % extract the topModel and selected system to scale from the
            % DesignSetting of the WorkflowSetting
            designSetting = workflowSetting.getSettingValue('DesignSetting');
            topModel = designSetting.TopModel;
            sud = designSetting.SelectedSystemToScale;
            
            % Given the ActionID, return the correct engine
            actionFactory = fxptui.internal.ActionFactory;
            switch keyword
                case {actionFactory.ApplyID, actionFactory.CollectID, actionFactory.PrepareID, actionFactory.ProposeID, actionFactory.VerifyID, actionFactory.CompareID}
                    % use the converter on FPTInstance
                    % TODO g2057490: move ShortcutManager to Dataset and have
                    % Converter read from it on creation so that this
                    % method doesn't rely on a FPT instance
                    fptInstance = fxptui.FixedPointTool.getExistingInstance();
                    engine = fptInstance.Converter;
                case {actionFactory.ExploreOptimizationID, actionFactory.OptimizeID}
                    % use DataTypeOptimization.OptimizationEngine as engine
                    optimizationOptions = workflowSetting.getSettingValue('OptimizationSetting');
                     [~, unsupportedBlocksExist] = fxptui.internal.utils.Utils.checkUnsupportedBlocks(topModel, sud, optimizationOptions);
                    engine = DataTypeOptimization.OptimizationEngineFactory.getEngine(topModel, sud, optimizationOptions, unsupportedBlocksExist);
                otherwise
                    % do not create engine when selected workflow action is
                    % optimization stop
                    engine = '';
            end
            
            
        end
        
    end
    
end
