function hooks = getBuildHooks(model)
%

%   Copyright 2014-2018 The MathWorks, Inc.

hooks = get_param(model, 'RTWBuildHooks');

% Ensure that we have the right set of fields
if isstruct(hooks)

    % Remove any hooks that are not enabled
    if isfield(hooks, 'enabled')
        lEnabled = {hooks.enabled};
        lEnabledLogical = strcmp(lEnabled, 'on');
        hooks = hooks(lEnabledLogical);
    end
    
    hookFields = fields(hooks);
    
    requiredFields = {
        'className', ...
        'excludedModels', ...
        'includeReferencedModels', ...
        'includeTopModel', ...
        'enabled', ...
        'argsAllComponents', ...
        'argsTopModelOnly'};
    
    % Strip off any non-required fields
    nonRequiredFields = setdiff(hookFields, requiredFields);
    if ~isempty(nonRequiredFields)
        hooks = rmfield(hooks, nonRequiredFields);
    end
end
