classdef (Sealed, Hidden) ClassHelpers
% CLASSHELPERS Class containing static helper methods regarding the 
% target data model classes that make up the Target Framework.

%   Copyright 2018-2022 The MathWorks, Inc.
    
    methods (Static)

        function types = getPublishedTargetClasses()
            types = targetframework.internal.user.commandline.matlab.Types.getTypeNames(Abstract = false, Enumeration = false, Hidden = false, IsA = "Data");
        end

        function types = getTargetObjectSubclasses()
            types = targetframework.internal.user.commandline.matlab.Types.getTypeNames(Abstract = false, Enumeration = false, Hidden = false, IsA = "Object");
        end

        function identifiers = getClassIdentifiers(className)
            
            classObjects = target.get(className);
            identifiers = {classObjects.Id};
        end
        
        function className = getFullyQualifiedName(className)
            
            if ~startsWith(className, "target.")
                className = "target." + string(className);
            end
        end
        
        function settableProperties = getClassSettableProperties(className)
            
            fullyQualifiedClassName = target.internal.ClassHelpers.getFullyQualifiedName(className);
            classMetaData = meta.class.fromName(fullyQualifiedClassName);
            settablePropertyIndices = strcmp({classMetaData.PropertyList.SetAccess}, 'public') & ~cellfun(@isempty,{classMetaData.PropertyList.SetMethod}) & ~[classMetaData.PropertyList.Hidden];
            settableProperties = {classMetaData.PropertyList(settablePropertyIndices).Name};
        end
        
        function options = getCreateOptions(className, name)

            arguments
                className (1, 1) string
                % We need to allow also non-scalar strings as when using
                % repeating tuples in functionSignatures.json, all the
                % first arguments of the tuple (the names in this case) are
                % passed to the "choices" function, i.e., this function.
                name (1, :) string
            end
            
            switch name(end)
                case "Copy"
                    options = target.internal.ClassHelpers.getClassIdentifiers(className);
                otherwise
                    options = "";
            end
        end
    end
end

% LocalWords:  TCP
