function remove(model, profile)
% CODER.PROFILE.REMOVE(MODEL, PROFILE)
% Remove the profile PROFILE from model MODEL in code perspective. After
% removing the profile, all of the constituent stereotypes will no longer
% be available.
% 
% Inputs:
%   model           Simulink model name or handle.
%
%   profile         profile name or file path.
%
% Example:
%    
%    coder.profile.remove('rtwdemo_counter', "ASAP2_Profile");

%   Copyright 2020 The MathWorks, Inc.

mappingType = coder.mapping.internal.Utils.getCurrentExternalMappingType(model);

slRoot = slroot;
if ~slRoot.isValidSlObject(model)
    DAStudio.error('coderdictionary:api:invalidSimulinkObject',...
        profile, 'model', model);
end
if ishandle(model)
    model = get_param(model, 'Name');
end

internalMappingType = coder.mapping.internal.Utils.getInternalMappingType(mappingType);
mapping = Simulink.CodeMapping.get(model, internalMappingType);

if isempty(mapping)
    DAStudio.error('coderdictionary:api:NoCodeMapping', model);
end
[isValid, msg, name] = coder.internal.ProfileStereotypeUtils.loadIfValidProfile(profile);
if isValid
    mapping.removeProfile(name);
    systemcomposer.internal.profile.Profile.unload(name);
else
    error(msg);
end
end

% LocalWords:  coderdictionary
