classdef PrepareHandler < fxptui.Web.CallbackService.ActionsHandler
    % Class to handle preparing the model from FPT.
    
    % Copyright 2019 The MathWorks, Inc.
    
    properties(Constant)
        ActionID = fxptui.internal.ActionFactory.PrepareID;
    end
    
    methods
        
        function prepare(~, varargin)
            % no op
        end
        
        function handleSuccess(~, varargin)
            fptInstance = varargin{1};
            
            % g1986173 - switch document view in UI
            dataController = fptInstance.getDataController();
            switchIntent = fxptui.message('setupPreparation');
            dataController.sendFPTUIDocumentSelection(switchIntent);
            
            % update the UI with the latest result
            analyzerController = fptInstance.getAnalyzerController;
            uiReport = analyzerController.compileReportFromCache();
            analyzerController.updateView(uiReport);
            
        end
        
        function handleError(this, varargin)
            
            fptInstance = varargin{2};
            
            % refresh run browser
            isError = true;
            this.refreshRunBrowser(fptInstance, isError);
            
            fxptui.showdialog('genericerror');
        end
        
        function cleanup(~, varargin)
            %no op
        end
        
    end
end
