classdef AutoscalerApplyStrategy < fxptds.WorkflowTopology.Strategy
    %% AUTOSCALERAPPLYSTRATEGY class
    
    % Copyright 2018-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)
            
            % Find the collection node (simulate or derived) used
            collectionName = this.FPTRunID;
            
            % create a new Apply Action node
            type = fxptds.WorkflowTopology.element.NodeType.ApplyAction;
            applyNode = this.createAndAddNodeByType(type);
            
            % declare the new node as the target
            applyName = applyNode.Name;
            
            % Get the most recent proposal for that run -- ex. user
            % proposes 16 WL, reproposes with 18 WL, Apply. Apply Action is
            % using the 18 WL settings
            query = this.createDefaultQuery();
            query.Type = "Proposal";
            query.Limit = 1;
            
            % executeQuery finds the most recently created proposal node
            % that is dependent on the first input (collectionName)
            extractedData = this.executeQuery(collectionName, query);
            proposeName = this.processQueryData(extractedData);
            
            % connect the Propose Action to the new Apply Action target
            this.verifyAndConnect(proposeName, applyName);
            
            % create a new AutoscalerDesign node
            type = fxptds.WorkflowTopology.element.NodeType.AutoscalerDesign;
            designNode = this.createAndAddNodeByType(type);
            
            % declare the new node as the target
            designName = designNode.Name;
            
            % connect the Propose Action to the new Apply Action target
            this.verifyAndConnect(applyName, designName);
            
        end
    end
    
end

