classdef (Abstract) Workflow < handle
    % Dynamic Workflow base class

%   Copyright 2022 The MathWorks, Inc.

    properties (Abstract, Constant)
        % every dynamic workflow must provide a WorkflowName
        WorkflowName
    end

    methods
        %constructor
        function obj = Workflow()

        end
    end

    %% methods to define HDLWA GUI tasks and the workflow task trees

    % Required methods for each dynamic workflow class
    methods (Abstract)

        % Create workflow task tree keys
        [key,keyTerms] = hdlwa_getWorkflowTaskKey(obj, hDI)

        % define workflow task tree list
        taskList = hdlwa_createTaskList(obj, keyTerms)

        % return true if the workflow has reference design tasks
        result = hdlwa_showReferenceDesignTasks(obj)

        % define extra HDLWA GUI tasks for this workflow
        nodes = hdlwa_defineTasks(obj, nodes, utilTaskTitle)

        % define extra HDLWA GUI checks for this workflow
        recordCellArray = hdlwa_defineChecks(obj, recordCellArray, publishFailedMessage, publishResults, utilDisplayResult)

        % adjust workflow when change parameters in set Target Device task
        hdlwa_utilAdjustWorkflowParameter(obj, mdladvObj, hDI)

        % adjust workflow when change parameter in Set Target Reference Design task
        hdlwa_utilAdjustTargetReferenceDesign(obj, mdladvObj, hDI)

    end

    %% Helper functions
    methods (Access = protected)

        function nodes = insertChildTaskUnderParentTask(obj, nodes, ...
                childTaskID, parentTaskID)
            % utility function to insert the task with childID under the
            % task with parentID.

            parentType = 'ModelAdvisor.Procedure';
            parentIdx                   = cellfun(@(x) (isa(x, parentType) && strcmp(x.ID, parentTaskID)), nodes);
            parentNode                  = nodes{parentIdx};
            parentNode.Children{end+1}  = childTaskID;
            nodes{parentIdx}            = parentNode;
        end

    end


end

% LocalWords:  HDLWA
