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