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