classdef OptimizedConversionStrategy < fxptds.WorkflowTopology.Strategy
    %% OPTIMIZEDCONVERSIONSTRATEGY class
    
    % Copyright 2019 The MathWorks, Inc.
    
    % Access is protected and extended to Facade and to the test class
    methods (Access = {?fxptds.WorkflowTopology.Strategy, ?fxptds.WorkflowTopology.Facade, ?WorkflowTopologyTestCase})
        function execute(this)
            
            % declare the rootName
            rootName = this.TopModel;
            targetName = this.FPTRunID;
            
            % starting at the root, find the most recent root or autoscaler
            % design that has been created
            query = this.createDefaultQuery();
            query.Type = "Design";
            query.Limit = 1;
            
            % execute the query and extract value from cell array
            extractedData = this.executeQuery(rootName, query);
            sourceName = this.processQueryData(extractedData);
            
            % in the event that fxpopt has been run twice both using the
            % same 'targetName', invalidate the target name and all
            % dependent nodes
            nodesToInvalidate = this.getNodesToInvalidate(targetName);
            this.invalidateNodes(nodesToInvalidate);
            
            % create a new OptimizationAction Node
            type = fxptds.WorkflowTopology.element.NodeType.OptimizationAction;
            this.createAndAddNodeByType(type);
            
            % connect the OptimizationAction to the latest Design
            this.verifyAndConnect(sourceName, targetName);
            
        end
        
    end
    
end

