import{__awaiter as t,__generator as i}from'./../../ext-esm/tslib/tslib.es6.js';import{postTask as r,getDataAppStorageAggregate as s,getTask as e}from"../../clients/jsonApi/index.js";import"../../constants/goals.js";import"../../constants/segment.js";import"../../constants/alerts.js";import"../../constants/apps.js";import"../../constants/drillstring.js";import"../../constants/completion.js";import"../../constants/appPackages.js";import"../../constants/notifications.js";import"../../constants/feed.js";import"../../constants/bha.js";import{CORVA_COMPANY_ID as n}from"../../constants/corvaCompanyId.js";import"lodash";import"../GradientManager/configuration/constants.js";import{METADATA as o}from"./constants.js";import"../../utils/index.js";import{showErrorNotification as a,showSuccessNotification as c}from"../../utils/notificationToasts.js";import{delay as l}from"../../utils/delay.js";function u(r){return t(this,void 0,void 0,(function(){var t;return i(this,(function(i){return t={match:JSON.stringify({company_id:n,"data.app_id":r}),limit:100,sort:JSON.stringify({timestamp:1}),project:JSON.stringify({app_id:"$data.app_id",rule_id:"$data.wcu_rules.rule_id",_id:0})},[2,s(o.recordProvider,o.recordCollections.wcuRuleMapping,t)]}))}))}function d(r){return t(this,void 0,void 0,(function(){var t;return i(this,(function(i){return t={sort:JSON.stringify({ts_desc:1}),match:JSON.stringify({company_id:n,"data.rule_id":{$in:r}}),limit:1e3},[2,s(o.recordProvider,o.recordCollections.wellnessRuleSettings,t)]}))}))}function p(r,e){return t(this,void 0,void 0,(function(){var t;return i(this,(function(i){return t={sort:JSON.stringify({timestamp:-1}),match:JSON.stringify({asset_id:{$in:r},"data.rule_id":{$in:e}}),limit:100},[2,s(o.recordProvider,o.recordCollections.wellnessAlerts,t)]}))}))}function m(r){return t(this,void 0,void 0,(function(){var t,s,n,o;return i(this,(function(i){switch(i.label){case 0:i.trys.push([0,7,,8]),t="initial",s=0,i.label=1;case 1:return"initial"===t?[3,3]:[4,l(1e3*(1+.2*s))];case 2:i.sent(),i.label=3;case 3:return[4,e(r)];case 4:n=i.sent(),t=null==n?void 0:n.state,s+=1,i.label=5;case 5:if("running"===t&&s<10)return[3,1];i.label=6;case 6:return"succeeded"===t?c("Data Quality Issue reported successfully!"):(console.error("Task execution exited"),a("Failed to report Data Quality Issue. Please try again later")),[3,8];case 7:return o=i.sent(),console.error("Failed to create a task; Error:",o),a("Failed to report Data Quality Issue. Please try again later"),[3,8];case 8:return[2]}}))}))}function f(s,e,o,a){var c;return t(this,void 0,void 0,(function(){var t,l;return i(this,(function(i){switch(i.label){case 0:return t={provider:"corva",app_key:"corva.wellness_helper",asset_id:s,properties:{type:"add_manual",internal:o.company_id===n,message:e,user_id:o.id,user_company_id:o.company_id,user_name:"".concat(o.first_name," ").concat(o.last_name),user_company_name:null===(c=o.company)||void 0===c?void 0:c.name,segment:a}},[4,r({task:t})];case 1:return[4,m(null==(l=i.sent())?void 0:l.id)];case 2:return i.sent(),[2]}}))}))}export{u as getWCURuleMapping,p as getWellnessAlerts,d as getWellnessRuleSettings,f as postReportError};
