function clusterInfo = shutdownCloudClusterOnEvent(clusterID, terminationPolicy)
% Shutdown a cloud cluster following a termination policy (on event).

%   Copyright 2020 The MathWorks, Inc.

cloudCenterClient = parallel.internal.cloud.currentCloudCenterClient();
assert(terminationPolicy == parallel.internal.types.TerminationPolicy.Never ||...
       terminationPolicy == parallel.internal.types.TerminationPolicy.Session ||...
       terminationPolicy == parallel.internal.types.TerminationPolicy.Idle);

shutdownCloudClusterFcn = @() cloudCenterClient.updateClusterShutdown(clusterID,...
                                                terminationPolicy.toCloudCenterName(), -1);
clusterInfoWithMessages = parallel.internal.mwa.invokeWithLogin(shutdownCloudClusterFcn);
parallel.internal.cloud.checkAndIssueWebServiceWarnings(clusterInfoWithMessages);

clusterInfo = clusterInfoWithMessages.data;
end