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