classdef (Hidden = true) RLSSILPILWrapperUtils < rtw.pil.SubsystemSILPILWrapperUtils
%RLSSILPILWRAPPERUTILS SIL/PIL RLS subsystem wrapper utilities
%
%   This is an undocumented class. Its methods and properties are likely to
%   change without warning from one release to the next.

%   Copyright 2020-2023 The MathWorks, Inc.
        
    methods
        % constructor
        function this = RLSSILPILWrapperUtils(silPILInterface, ...
                                            infoStruct, ...
                                            clientInterface,...
                                            topModelOriginalParams, ...
                                            lXilCompInfo)

            % call super class constructor                             
            this@rtw.pil.SubsystemSILPILWrapperUtils(silPILInterface, ...
                                            infoStruct, ...
                                            clientInterface, ...
                                            topModelOriginalParams, ...
                                            lXilCompInfo);
                                        
            unsupportedConfigSetParams = repmat(struct('Name', '', 'Value', ''), 1, 2);
            unsupportedConfigSetParams(1).Name = 'GroupInternalDataByFunction';
            unsupportedConfigSetParams(1).Value = 'on';
            unsupportedConfigSetParams(2).Name = 'PassReuseOutputArgsAs';
            unsupportedConfigSetParams(2).Value = 'Structure reference';
            if strcmp(this.getParam(unsupportedConfigSetParams(1).Name), unsupportedConfigSetParams(1).Value) && ...
                    strcmp(this.getParam(unsupportedConfigSetParams(2).Name), unsupportedConfigSetParams(2).Value)
                
                functionInterface = this.getSILPILInterface.getRootModel();
                subsystem = this.getComponentForDiagnostics();
                e = MSLException(message('PIL:pil_subsystem:UnsupportedDataLayout', ...
                    functionInterface, ...
                    subsystem, ...
                    unsupportedConfigSetParams(1).Name, ...
                    unsupportedConfigSetParams(2).Name, ...
                    unsupportedConfigSetParams(1).Value, ...
                    unsupportedConfigSetParams(2).Value));
                e.throw;
            end
        end
        
        function isReadOnly = isComponentReadOnly(~)
            % RLS simulation are always ReadOnly because the code is
            % generated in advance and FunctionInterface models are not
            % directly accessible to users
            isReadOnly = true;
        end
    end
    
    methods(Access = 'protected')
        function validateExportedParameters(this)
            % error out for exported parameters, at the moment the only
            % exported storage class supported by RLS is 'ExportToFile'.
            params = this.getCodeInfo.Parameters;
            exportedParams = false(size(params));
            for idx=1:length(params)
                storageImpl = this.getBaseStorageImplementation(params(idx).Implementation);
                owner = rtw.pil.OwnerAccessor.getOwner(storageImpl);
                if ~isempty(owner)
                    exportedParams(idx) = true;
                end
            end
            
            if any(exportedParams)
                exportedParamNames = {params(exportedParams).GraphicalName};
                e = MSLException(message('PIL:pil_subsystem:UnsupportedParameter', ...
                    strjoin(exportedParamNames, ', ')));
                e.throw;
            end
        end

        function reportUnsupportedDataStoreReference(this, isModelReferenceTarget, referenceDataStore)  
            % TopTester: matlab/test/toolbox/rtw/targets/ert/pil/subsystem/rls/tRLS_DSM.m
            assert(~isModelReferenceTarget, 'RLS workflow does not use model reference target!');
            MSLDiagnostic('PIL:pil_subsystem:DataStoreReferenceRLS', ...
                        this.getComponentForDiagnostics, referenceDataStore).reportAsWarning();
        end        
    end
end
