import t from"@babel/runtime/helpers/toConsumableArray";import e from"@babel/runtime/helpers/asyncToGenerator";import r from"@babel/runtime/regenerator";import{range as a,sortBy as n,get as s}from"lodash";import{METRICS_KEYS as i}from"../constants.js";import{getCompanies as u,getAssets as o,getCompanyGoals as c,getAppStorage as p}from"../../../clients/jsonApi/index.js";function l(){return m.apply(this,arguments)}function m(){return(m=e(r.mark((function t(){var e;return r.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,u();case 3:e=t.sent,t.next=9;break;case 6:t.prev=6,t.t0=t.catch(0),console.error(t.t0);case 9:return t.abrupt("return",e?n(e,["name"]):[]);case 10:case"end":return t.stop()}}),t,null,[[0,6]])})))).apply(this,arguments)}function f(t,e){return b.apply(this,arguments)}function b(){return(b=e(r.mark((function t(e,a){var n,i,u;return r.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=null,t.prev=1,t.next=4,o({types:["well"],company_id:e?+e:void 0,fields:["asset.name","asset.parent_asset_id","asset.parent_asset_name","asset.stats","asset.target_formation","asset.string_design","asset.root_asset_name","asset.basin","asset.county","asset.area","asset.visibility","asset.top_hole"],per_page:1e4,sort:"name"});case 4:n=t.sent,t.next=10;break;case 7:t.prev=7,t.t0=t.catch(1),console.error(t.t0);case 10:if(i=n?n.data.map((function(t){return{id:Number(t.id),name:s(t,"attributes.name"),rigId:s(t,"attributes.parent_asset_id")||"Null",rigName:s(t,"attributes.parent_asset_name")||"Null",formation:s(t,"attributes.target_formation")||"Null",stringDesign:s(t,"attributes.string_design")||"Null",programName:s(t,"attributes.root_asset_name")||"Null",basin:s(t,"attributes.basin")||"Null",county:s(t,"attributes.county")||"Null",area:s(t,"attributes.area")||"Null",visibility:s(t,"attributes.visibility"),topHole:s(t,"attributes.top_hole"),rigReleaseDate:s(t,"attributes.stats.well_end"),totalDepth:s(t,"attributes.stats.total_depth"),is_usable:!0}})).filter((function(t){return"visible"===t.visibility})):[],!a){t.next=16;break}return t.next=14,a(i);case 14:return u=t.sent,t.abrupt("return",u);case 16:return t.abrupt("return",i);case 17:case"end":return t.stop()}}),t,null,[[1,7]])})))).apply(this,arguments)}function d(t){return h.apply(this,arguments)}function h(){return(h=e(r.mark((function t(e){var a;return r.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,c(e);case 3:a=t.sent,t.next=9;break;case 6:t.prev=6,t.t0=t.catch(0),console.error(t.t0);case 9:return t.abrupt("return",a&&s(a,"company_goals")||{});case 10:case"end":return t.stop()}}),t,null,[[0,6]])})))).apply(this,arguments)}function _(t,e){return v.apply(this,arguments)}function v(){return v=e(r.mark((function n(s,u){var o,c,l;return r.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(0!==u.length){n.next=2;break}return n.abrupt("return",[]);case 2:return o=Math.floor(u.length/200)+1,n.next=5,Promise.all(a(o).map(function(){var t=e(r.mark((function t(e,a){var n,o,c,l;return r.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n={company_id:s,"data.asset_id":{$in:u.slice(200*a,200*(a+1))},"data.key":{$in:i},"data.type":"asset"},o={_id:0,"data.key":1,"data.value":1,asset_id:"$data.asset_id"},c={aggregate:JSON.stringify([{$match:n},{$project:o}])},l=null,t.prev=4,t.next=7,p("corva","metrics",null,c);case 7:l=t.sent,t.next=13;break;case 10:t.prev=10,t.t0=t.catch(4),console.error(t.t0);case 13:return t.abrupt("return",l||[]);case 14:case"end":return t.stop()}}),t,null,[[4,10]])})));return function(e,r){return t.apply(this,arguments)}}()));case 5:return c=n.sent,l=[],c.forEach((function(e){return l.push.apply(l,t(e))})),n.abrupt("return",l);case 9:case"end":return n.stop()}}),n)}))),v.apply(this,arguments)}export{l as fetchCompanies,d as fetchCompanyGoals,_ as fetchMetricsData,f as fetchWells};
