"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("lodash"),r=require("./constants.js");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=n(e);function u(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?u(Object(r),!0).forEach((function(t){s.default(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):u(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var o=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return e.toLowerCase()===r.ALERT_STATUSES.RESOLVED};var i=function(e){var t=e.assetId,r=e.wellHubSlug;return"/assets/".concat(t,"/").concat(r,"/Data Quality")},c=function(e,t){return e.reduce((function(e,n){if(!n)return e;if([r.ALERT_STATUSES.FLAGGED,r.ALERT_STATUSES.INVESTIGATION,r.ALERT_STATUSES.ON_HOLD].includes(n.status))return e;var s=t.find((function(e){return e.id===n.assetId}));if(!s)return e;var u=s.name;return e[u]||(e[u]=[]),e[u].push(n),e}),{})};exports.getCategoryIconType=function(e){return e.some((function(e){return e.missingNum>0}))?r.BADGE_ICON_STATUSES.error:e.some((function(e){return e.issuesNum>0}))?r.BADGE_ICON_STATUSES.issue:r.BADGE_ICON_STATUSES.resolved},exports.getDeductsFromScoreClass=function(e,t,r){return r||!t?"":t>40?e.error:t>10?e.warn:t>5?e.ok:e.good},exports.getDeductsFromScoreValue=function(e,t){return!t&&null!=e&&e>=0?"".concat(e,"%"):"—"},exports.getIconType=function(e,t){return e.filter((function(e){return t[e].every((function(e){return e.isResolved}))})).length===e.length?r.BADGE_ICON_STATUSES.success:e.filter((function(e){return t[e].some((function(e){return e.missingNum}))})).length?r.BADGE_ICON_STATUSES.error:e.filter((function(e){return t[e].some((function(e){return e.issuesNum}))})).length?r.BADGE_ICON_STATUSES.issue:""},exports.getLinkToDQPage=i,exports.getNewWellnessAlerts=function(e){var t=e.assetsList,n=e.alertsGroupByRuleId,s=e.wellnessRuleSettings,u=e.wellHubSlug;return n.reduce((function(e,n){if(null==n||!n.length)return e;var l=c(n,t);return Object.keys(l).forEach((function(t){var n=l[t],c=s.find((function(e){var t=e.data;return(null==t?void 0:t.rule_id)===n[0].ruleId}));if(c){var d=c.data.customer_name||n[0].name,f=c.data.customer_category||n[0].category,S=n.find((function(e){return e.status===r.ALERT_STATUSES.OPEN||e.status===r.ALERT_STATUSES.EXPIRED})),g=n.every((function(e){return o(e.status)}));e[t]||(e[t]=[]),e[t].push({alert:a(a({},g?a(a({},n.sort((function(e,t){return t.statusUpdatedAt-e.statusUpdatedAt}))[0]),{},{emptyMessage:r.DATA_QUALITY_CHECK_PASSED}):S),{},{name:d,category:f}),isResolved:g,id:n[0].id,issuesNum:n.filter((function(e){return e.state===r.ALERT_STATES.issue&&!o(e.status)})).length,name:d,missingNum:n.filter((function(e){return e.state===r.ALERT_STATES.missing&&!o(e.status)})).length,linkToDQPage:i({assetId:n[0].assetId,wellHubSlug:u})})}})),e}),{})},exports.getSortedWellnessAlerts=function(e,r){return e.reduce((function(e,n){return a(a({},e),{},s.default({},n,t.sortBy(r[n],[function(e){return-e.missingNum},function(e){return-e.issuesNum},function(e){return e.alert.category},function(e){return e.name}])))}),{})},exports.groupAlertsByAssetName=c,exports.isResolved=o,exports.parseWellnessAlertFromJson=function(e){var t,r,n,s;return"Issue"===e.data.state&&"Manual Alert"!==e.data.name&&"User Created"!==e.data.category?null:{id:e._id,assetId:e.asset_id,name:e.data.name,category:e.data.category,lastCheckedAt:e.data.last_checked_at,ruleId:e.data.rule_id,message:e.data.message,status:(s=e.data.status,"under investigation"===s?"investigation":["not available","resolved"].includes(s)?"resolved":s),statusReason:e.data.status_reason,statusUpdatedAt:e.data.status_updated_at,state:(n=e.data.state,["Fatal","Critical","Issue","Manual"].includes(n)?"Issue":["Missing Data"].includes(n)?"Missing":"Unknown"),createdAt:e.timestamp,note:e.data.note,isThrottled:e.data.is_throttled,segment:e.data.segment,metrics:{holeDepth:null===(t=e.data.metrics)||void 0===t?void 0:t.hole_depth,state:null===(r=e.data.metrics)||void 0===r?void 0:r.state},deductsFromScore:e.data.deducts_from_score}};
//# sourceMappingURL=utils.js.map
