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