"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require('./../../ext-esm/tslib/tslib.es6.js'),e=require("lodash"),s=require("./constants.js"),n=function(t){return void 0===t&&(t=""),t.toLowerCase()===s.ALERT_STATUSES.RESOLVED};var r=function(t){var e=t.assetId,s=t.wellHubSlug;return"/assets/".concat(e,"/").concat(s,"/Data Quality")},a=function(t,e){return t.reduce((function(t,n){if(!n)return t;if([s.ALERT_STATUSES.FLAGGED,s.ALERT_STATUSES.INVESTIGATION,s.ALERT_STATUSES.ON_HOLD].includes(n.status))return t;var r=e.find((function(t){return t.id===n.assetId})).name;return t[r]||(t[r]=[]),t[r].push(n),t}),{})};exports.findUpdatedFields=function(t,s){return e.omitBy(s,(function(s,n){return e.isEqual(s,t[n])}))},exports.getCategoryIconType=function(t){return t.some((function(t){return t.missingNum>0}))?s.BADGE_ICON_STATUSES.error:t.some((function(t){return t.issuesNum>0}))?s.BADGE_ICON_STATUSES.issue:s.BADGE_ICON_STATUSES.resolved},exports.getDeductsFromScoreClass=function(t,e,s){return s||!e?"":e>40?t.error:e>10?t.warn:e>5?t.ok:t.good},exports.getDeductsFromScoreValue=function(t,e){return!e&&t>=0?"".concat(t,"%"):"—"},exports.getIconType=function(t,e){return t.filter((function(t){return e[t].every((function(t){return t.isResolved}))})).length===t.length?s.BADGE_ICON_STATUSES.success:t.filter((function(t){return e[t].some((function(t){return t.missingNum}))})).length?s.BADGE_ICON_STATUSES.error:t.filter((function(t){return e[t].some((function(t){return t.issuesNum}))})).length?s.BADGE_ICON_STATUSES.issue:""},exports.getLinkToDQPage=r,exports.getNewWellnessAlerts=function(e){var u=e.assetsList,i=e.alertsGroupByRuleId,o=e.wellnessRuleSettings,d=e.wellHubSlug,l=i.reduce((function(e,i){if(!(null==i?void 0:i.length))return e;var l=a(i,u);return Object.keys(l).forEach((function(a){var u=l[a],i=o.find((function(t){var e=t.data;return(null==e?void 0:e.rule_id)===u[0].ruleId})),c=i.data.customer_name||u[0].name,_=i.data.customer_category||u[0].category,S=u.find((function(t){return t.status===s.ALERT_STATUSES.OPEN||t.status===s.ALERT_STATUSES.EXPIRED})),f=u.every((function(t){return n(t.status)}));e[a]||(e[a]=[]),e[a].push({alert:t.__assign(t.__assign({},f?t.__assign(t.__assign({},u.sort((function(t,e){return e.statusUpdatedAt-t.statusUpdatedAt}))[0]),{emptyMessage:s.DATA_QUALITY_CHECK_PASSED}):S),{name:c,category:_}),isResolved:f,id:u[0].id,issuesNum:u.filter((function(t){return t.state===s.ALERT_STATES.issue&&!n(t.status)})).length,name:c,missingNum:u.filter((function(t){return t.state===s.ALERT_STATES.missing&&!n(t.status)})).length,linkToDQPage:r({assetId:u[0].assetId,wellHubSlug:d})})})),e}),{});return l},exports.getSortedWellnessAlerts=function(s,n){return s.reduce((function(s,r){var a;return t.__assign(t.__assign({},s),((a={})[r]=e.sortBy(n[r],[function(t){return-t.missingNum},function(t){return-t.issuesNum},function(t){return t.alert.category},function(t){return t.name}]),a))}),{})},exports.groupAlertsByAssetName=a,exports.hasOnlyLastCheckedAtKey=function(t){return e.isEqual(e.keys(t),["lastCheckedAt"])},exports.isResolved=n,exports.parseWellnessAlertFromJson=function(t){var e,s,n,r;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:(r=t.data.status,"under investigation"===r?"investigation":["not available","resolved"].includes(r)?"resolved":r),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===(s=t.data.metrics)||void 0===s?void 0:s.state},deductsFromScore:t.data.deducts_from_score}};
