"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/slicedToArray"),t=require("@babel/runtime/helpers/defineProperty"),r=require("@babel/runtime/helpers/asyncToGenerator"),n=require("@babel/runtime/helpers/toConsumableArray"),a=require("@babel/runtime/regenerator"),s=require("lodash"),i=require("./utils.js"),u=require("./constants.js"),c=require("../../../../constants/assetTypes.js");function p(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=p(e),l=p(t),o=p(r),f=p(n),A=p(a);function S(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function y(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?S(Object(r),!0).forEach((function(t){l.default(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):S(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var g=[u.APPS_DATA_REQUESTS.WELLS,u.APPS_DATA_REQUESTS.RIGS,u.APPS_DATA_REQUESTS.FRAC_FLEETS,u.APPS_DATA_REQUESTS.FRAC_FLEET_WELLS,u.APPS_DATA_REQUESTS.PAD_WELLS],E=function(e,t){var r=e.reduce((function(e,r){if(i.isAppWithSettings(r))return e;var n=i.getAppAssetSpecificTypeId(r,"deprecatedAssetId");return e.add(n||t),e}),new Set);return f.default(r)};function b(e,t){return h.apply(this,arguments)}function h(){return(h=o.default(A.default.mark((function e(t,r){var n,a,s,u,p,d,o;return A.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=r.current.deprecatedAssetData,a=Object.keys(n),(s=t.filter((function(e){return!a.includes(String(e))}))).length){e.next=5;break}return e.abrupt("return",n);case 5:return e.next=7,i.fetchAssetEntitiesByAssetIds(s);case 7:if(u=e.sent){e.next=10;break}return e.abrupt("return",n);case 10:return p={rig:c.ASSET_TYPES.rig.id,well:c.ASSET_TYPES.well.id},d=Object.values(u).flat().reduce((function(e,t){var r=t.data;return e[r.attributes.asset_id]=l.default({},p[r.type],r.id),e}),{}),o=y(y({},n),d),r.current.cachedDeprecatedAssetData=o,e.abrupt("return",o);case 15:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function P(e,t,r){return _.apply(this,arguments)}function _(){return(_=o.default(A.default.mark((function e(t,r,n){var a;return A.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,b(E(t,r),n);case 2:return a=e.sent,e.abrupt("return",t.map((function(e){if(i.isAppWithSettings(e))return e;var t=i.getAppAssetSpecificTypeId(e,"deprecatedAssetId");return y(y({},e),{},{settings:a[t||r]})})));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function T(){return(T=o.default(A.default.mark((function e(t){var r,n,a,c,p,l,o,f,S,E,b,h,_,T,v,D,F,I,m,w,R,O,j,L,W,B,x,q,U,k;return A.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.apps,n=t.dashboardAssetId,a=t.cache,c=t.updateCache,p=t.requests,l=void 0===p?g:p,e.next=3,P(r,n,a);case 3:return o=e.sent,f=i.prepareDataForResolver(o,a),S=f.appsWellIds,E=f.appsRigIds,b=f.appsFracFleetIds,h=f.appsFracFleetToFetchWellsIds,_=f.appsPadIds,T=f.uniqueWellIds,v=f.uniqueRigIds,D=f.uniqueFFIds,e.next=7,Promise.all([l.includes(u.APPS_DATA_REQUESTS.WELLS)&&i.fetchWells(T),l.includes(u.APPS_DATA_REQUESTS.RIGS)&&i.fetchRigs(v),l.includes(u.APPS_DATA_REQUESTS.FRAC_FLEETS)&&i.fetchFracFleets(D),l.includes(u.APPS_DATA_REQUESTS.FRAC_FLEET_WELLS)&&i.fetchFracFleetWells(h,r),l.includes(u.APPS_DATA_REQUESTS.PAD_WELLS)&&i.fetchPadWells(_,r)]);case 7:return F=e.sent,I=d.default(F,5),m=I[0],w=I[1],R=I[2],O=I[3],j=I[4],L=(null==m?void 0:m.data)&&s.keyBy(m.data.map((function(e){var t=s.get(e,"relationships.rig.data.id"),r=s.get(e,"relationships.program.data.id"),n=m.included.find((function(e){return"rig"===e.type&&e.id===t})),a=m.included.find((function(e){return"program"===e.type&&e.id===r}));return y(y({},e),{},{rig:y(y({},n),{},{program:a})})})),"id"),W=(null==w?void 0:w.data)&&s.keyBy(w.data.map((function(e){var t=s.get(e,"relationships.active_well.data.id")||s.get(e,"relationships.last_active_well.data.id"),r=s.get(e,"relationships.program.data.id"),n=w.included.find((function(e){return"well"===e.type&&e.id===t})),a=w.included.find((function(e){return"program"===e.type&&e.id===r}));return y(y({},e),{},{well:n,program:a})})),"id"),B=R&&s.keyBy(R,"id"),c({wellsById:L||{},rigsById:W||{},fracFleetsById:B||{}}),x=i.getAppsDataByWells(S,a.current.wellsById),q=i.getAppsDataByRigs(E,a.current.rigsById),U=i.getAppsDataByFFs(b,a.current.fracFleetsById,O),k=i.getAppsDataByPads(_,j),e.abrupt("return",s.merge(x,q,U,k));case 23:case"end":return e.stop()}}),e)})))).apply(this,arguments)}exports.getAppSettingsByDeprecatedAssetId=b,exports.getAppsWithUnifiedSettings=P,exports.getDeprecatedAssetIds=E,exports.resolveAppsData=function(e){return T.apply(this,arguments)};
