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