classdef ExcelAddinWriter < compiler.internal.mcc.MccDependencyWriter
    %EXCELADDINWRITER Writes the mcc command to generate an Excel Add-in
    
%   Copyright 2020-2021 The MathWorks, Inc.
    
    % define abstract
    properties(Constant,Access = protected)
        OptionsClass = 'compiler.build.ExcelAddInOptions'
    end
    
    methods
        function obj = ExcelAddinWriter(options)
             obj = obj@compiler.internal.mcc.MccDependencyWriter(options);
        end
    end
    
    methods(Access= protected)        
        function addTargetCommands(obj)
            if obj.Options.GenerateVisualBasicFile
                obj.addCommand("-b")
            end
            
            if obj.Options.DebugBuild
                obj.addCommand("-g")
            end
            
            if ~obj.Options.EmbedArchive
                obj.addCommand("-C")
            end
        end
           
        function addPostDashWCommands(obj)  
            
            dashWString = "excel:" + string(obj.Options.AddInName) + ...
                "," + string(obj.Options.ClassName);
            if ispc
                dashWString = dashWString + ...
                    ",version=" + string(obj.Options.AddInVersion);
            end
            obj.addCommand(dashWString)
        end
        
        function addDashTCommands(obj)
            obj.addCommand("-T")
            obj.addCommand("link:lib")
        end
        
        function writeCommandForFiles(obj)
            exports = obj.Options.FunctionFiles;
            for n = 1:numel(exports)
                obj.addCommand(string(exports{n}))
            end
        end
    end
    
end
