class UsageLoggingUtil {

    public void logClusterStatusChangeUsageEvent(@Nullable Status oldClusterStatus, @Nullable Cluster cluster) {
        if (oldClusterStatus == null || cluster == null || cluster.getId() == null || cluster.getStatus() == null) {
            return;
        }
        Stack stack = cluster.getStack();
        if (stack == null) {
            return;
        }
        UsageProto.CDPCloudbreakClusterStatus.Value oldStatusEnum = null;
        UsageProto.CDPCloudbreakClusterStatus.Value newStatusEnum = null;
        try {
            oldStatusEnum = UsageProto.CDPCloudbreakClusterStatus.Value.valueOf(
                    oldClusterStatus.name().toUpperCase());
            newStatusEnum = UsageProto.CDPCloudbreakClusterStatus.Value.valueOf(
                    cluster.getStatus().name().toUpperCase());
        } catch (IllegalArgumentException e) {
            return;
        }
        if (oldStatusEnum == newStatusEnum) {
            return;
        }
        // Datahub clusters will have datalake resource id set.
        if (stack.getDatalakeResourceId() != null) {
            UsageProto.CDPDatahubClusterStatusChanged proto = UsageProto.CDPDatahubClusterStatusChanged.newBuilder()
                    .setClusterId(cluster.getId().toString())
                    .setOldStatus(oldStatusEnum)
                    .setNewStatus(newStatusEnum)
                    .build();
            usageReporter.cdpDatahubClusterStatusChanged(proto);
        } else {
            UsageProto.CDPDatalakeClusterStatusChanged proto = UsageProto.CDPDatalakeClusterStatusChanged.newBuilder()
                    .setDatalakeId(cluster.getId().toString())
                    .setOldStatus(oldStatusEnum)
                    .setNewStatus(newStatusEnum)
                    .build();
            usageReporter.cdpDatalakeClusterStatusChanged(proto);
        }
    }

}