classdef WebAppArchiveOptions < compiler.internal.build.DependencyOptions
%COMPILER.BUILD.WEBAPPARCHIVEOPTIONS  Create a web app options object
%
%    OPTS = COMPILER.BUILD.WEBAPPARCHIVEOPTIONS(APPFILE) creates a default
%        WEBAPPARCHIVEOPTIONS object OPTS with a MATLAB app specified by
%        APPFILE. The WEBAPPARCHIVEOPTIONS object is passed as an input to
%        the compiler.build.webAppArchive function.
%
%    OPTS = COMPILER.BUILD.WEBAPPARCHIVEOPTIONS(APPFILE,NAME,VALUE)
%        creates a WEBAPPARCHIVEOPTIONS object OPTS with a MATLAB app
%        specified by APPFILE and additional customizations specified by
%        name-value pairs. The WEBAPPARCHIVEOPTIONS object is passed as an
%        input to the compiler.build.webAppArchive function.
%
%    INPUT ARGUMENTS:
%
%    - APPFILE (A row char vector or a string scalar)
%        Path to a MATLAB app. It must be an mlapp file.
%
%    OUTPUT ARGUMENTS:
%
%    - OPTS (A scalar compiler.build.WebAppArchiveOptions object)
%        Web app options, specified as a WebAppArchiveOptions object.
%
%    NAME-VALUE PAIR ARGUMENTS:
%
%    - AdditionalFiles (A row char vector, a string vector, or a cellstr vector)
%        A list of files and folders to be included within the web app
%        archive.
%
%    - ArchiveName (A row char vector or a string scalar)
%        Name of the generated archive.
%
%    - AutoDetectDataFiles ('on'/'off', true/false, or 1/0)
%        Binary value controlling whether data files that are provided as
%        inputs to certain functions (such as load) are automatically
%        included with the web app archive. This is set to 'on' by default.
%        If it is set to false/'off'/0, all data files must be added to the
%        application using the AdditionalFiles property.
%
%    - ObfuscateArchive ('on'/'off', true/false, or 1/0)
%        Binary value controlling whether to obfuscate the folder structures, 
%        file names and .m files in the deployable archive (.ctf file). 
%        This is set to 'off' by default.
%
%    - OutputDir (A row char vector or a string scalar)
%        Path to folder where the build files are saved.
%
%    - SupportPackages (A row char vector, a string vector, or a cellstr vector)
%        'autodetect' (default) - The required support packages are
%        detected and included automatically.
%
%        'none' - No support packages are included in the archive.
%
%        Otherwise, a specific list of support packages may be specified
%        for inclusion.
%
%    - Verbose ('on'/'off', true/false, or 1/0)
%        Binary value controlling build verbosity. This is set to 'off' by
%        default.
%
%    EXAMPLES:
%
%    % Create a WEBAPPARCHIVEOPTIONS object with a MATLAB app.
%    opts = COMPILER.BUILD.WEBAPPARCHIVEOPTIONS('exampleApp.mlapp');
%
%    % Create a WEBAPPARCHIVEOPTIONS object with a MATLAB app and
%    % additional options specified as name-value pairs.
%    opts = COMPILER.BUILD.WEBAPPARCHIVEOPTIONS('exampleApp.mlapp', ...
%        'AdditionalFiles','data.mat','Verbose','on');
%
%    % Create a WEBAPPARCHIVEOPTIONS object with a MATLAB app and
%    % additional options specified using dot notation.
%    opts = COMPILER.BUILD.WEBAPPARCHIVEOPTIONS('exampleFcn.mlapp');
%    opts.AdditionalFiles = 'data.mat';
%    opts.Verbose = 'on';
%
%    See also compiler.build.webAppArchive

%   Copyright 2020-2022 The MathWorks, Inc.
    
    % public
    properties
        AppFile
        ArchiveName = ''
    end
        
    % constructor
    methods
        function obj = WebAppArchiveOptions(main,varargin)
            
            narginchk(1,2*numel(properties(compiler.build.WebAppArchiveOptions.empty))-1)
            
            obj = obj@compiler.internal.build.DependencyOptions;
            
            obj.AppFile = main;
            
            p = inputParser;
            allprops = properties(obj);
            for n = 1:numel(allprops)
                addParameter(p,allprops{n},obj.(allprops{n}))
            end
            parse(p,varargin{:})
            changedprops = setdiff(allprops,p.UsingDefaults);
            
            for n = 1:numel(changedprops)
                obj.(changedprops{n}) = p.Results.(changedprops{n});
            end
        end
    end
    
    % set
    methods
        function obj = set.AppFile(obj,appFile)
            compiler.internal.validate.propertyIsScalarText(appFile,'AppFile')
            mustBeNonempty(appFile)
            compiler.internal.validate.fileMustExist(appFile)
            [~,~,ext] = fileparts(appFile);
            if ~isequal(ext,'.mlapp')
                error(message('Compiler:clishared:badExtension','AppFile','.mlapp'))
            end
            
            obj.AppFile = compiler.internal.validate.makePathAbsolute(appFile);
        end
        
        function obj = set.ArchiveName(obj,newName)
            compiler.internal.validate.cliName(newName,'ArchiveName')
            obj.ArchiveName = char(newName);
        end
    end
    
    % get
    methods
        function name = get.ArchiveName(obj)
            name = obj.ArchiveName;
            if isempty(name)
                [~,name] = fileparts(obj.AppFile);
            end
        end
    end
    
    % define abstract
    methods(Hidden)        
        function name = getName(obj)
            name = obj.ArchiveName;
        end
    end
    properties(Access = protected,Constant)
        OutputDirTag = char(compiler.internal.build.BuildTypes.webAppArchive)
    end
end
