classdef WorkflowSettingFactory < handle
    % WORKFLOWSETTINGFACTORY Each Workflow needs a different set of objects
    % to execute the workflow steps. WorkflowSettingFactory creates a
    % WorkflowSetting with the keys representing keywords of the objects
    % used and values being the actual setting objects
    
    %   Copyright 2019-2020 The MathWorks, Inc.
    
    methods
        
        function workflowSetting = getWorkflowSetting(this, intent)
            
            % given an intent, get the keys
            keys = this.getKeysFromIntent(intent);
            
            % get a cell array of corresponding value for each key
            values = this.getValuesFromKeys(keys);
            
            % create a WorkflowSetting and set the keys and values
            workflowSetting = fxptui.internal.workflowsetting.WorkflowSetting;
            workflowSetting.setKeys(keys);
            workflowSetting.setValues(values);
            
        end
        
        function keys = getKeysFromIntent(~, intent)
            % keys represent the keyword for each object needed in each
            % workflow
            switch intent
                case 'Collection'
                    keys = {'DesignSetting', 'CollectionSetting', 'VerificationSetting'};
                case 'IterativeConversion'
                    keys = {'DesignSetting', 'CollectionSetting', 'ProposalSetting', 'VerificationSetting'};
                case 'OptimizedConversion'
                    keys = {'DesignSetting', 'OptimizationSetting', 'ExploreSetting'};
                otherwise
                    keys = {};
            end
        end
        
        function values = getValuesFromKeys(this, keys)
            % given all the keys produce a cell array of its corresponding
            % values
            values = cell(size(keys));
            for idx = 1:numel(keys)
                key = keys{idx};
                value = this.getValueFromKey(key);
                values{idx} = value;
            end
        end
        
        function value = getValueFromKey(~, key)
            % for each key, return an instance of the underlying object
            % that hold all the information for the workflow
            switch key
                case {'CollectionSetting', 'VerificationSetting'}
                    value = DataTypeWorkflow.CollectionSettings;
                case 'ProposalSetting'
                    value = DataTypeWorkflow.ProposalSettings;
                case 'OptimizationSetting'
                    if fixed.internal.utility.featuremanager.FeatureManager.getStatus('fxpoptStopInFPT')
                        value = fxpOptimizationOptions('VerbosityStream', 'ToFixedPointTool');
                    else
                        value = fxpOptimizationOptions;
                    end
                case 'DesignSetting'
                    value = DataTypeWorkflow.DesignEnvironment;
                case 'ExploreSetting'
                    value = fxptui.internal.workflowsetting.ExploreSetting;
                    
            end
        end
    end
    
end

% LocalWords:  FPT
