/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as e}from"tslib";import{unique as t}from"../core/arrayUtils.js";import r from"../core/Error.js";import{JSONSupport as i}from"../core/JSONSupport.js";import{property as s,subclass as n}from"../core/accessorSupport/decorators.js";import{emitApplyEditsEvent as o}from"../layers/mixins/EditBusLayer.js";import d from"./UtilityNetwork.js";import{isVersionInEditSession as a,currentSessionId as l,isSafeToEditVersion as u}from"../versionManagement/support/versionManagementUtils.js";let c=class extends i{constructor(e){super(e),this.utilityNetwork=null}get networkServiceUrl(){return this.utilityNetwork?.networkServiceUrl??null}get featureServiceUrl(){return this.utilityNetwork?.featureServiceUrl??null}get gdbVersion(){return this.utilityNetwork?.gdbVersion??null}get historicMoment(){return this.utilityNetwork?.historicMoment??null}async reserve(e,t,r){const[{reserve:i},{default:s}]=await Promise.all([import("../rest/networks/unitIdentifiers/reserve.js"),import("../rest/networks/unitIdentifiers/support/ReserveParameters.js")]),n=new s({object:e,firstUnit:t,lastUnit:r});a(this.featureServiceUrl,this.gdbVersion||null)?(n.sessionId=l,await u(this.featureServiceUrl,this.gdbVersion,!0)):n.sessionId=null,n.gdbVersion=this.gdbVersion;const d=o(this.featureServiceUrl,null,this.gdbVersion,!1),c=await i(this.networkServiceUrl,n);d.resolve({edits:null,addedFeatures:[],updatedFeatures:[],deletedFeatures:[],addedAttachments:[],updatedAttachments:[],deletedAttachments:[],exceededTransferLimit:c.exceededTransferLimit,historicMoment:c.moment,editedFeatures:c.serviceEdits||void 0})}async reset(e){const[{reset:t},{default:r}]=await Promise.all([import("../rest/networks/unitIdentifiers/reset.js"),import("../rest/networks/unitIdentifiers/support/ResetParameters.js")]),i=new r({objects:e});a(this.featureServiceUrl,this.gdbVersion||null)?(i.sessionId=l,await u(this.featureServiceUrl,this.gdbVersion,!0)):i.sessionId=null,i.gdbVersion=this.gdbVersion;const s=o(this.featureServiceUrl,null,this.gdbVersion,!1),n=await t(this.networkServiceUrl,i);s.resolve({edits:null,addedFeatures:[],updatedFeatures:[],deletedFeatures:[],addedAttachments:[],updatedAttachments:[],deletedAttachments:[],exceededTransferLimit:n.exceededTransferLimit,historicMoment:n.moment,editedFeatures:n.serviceEdits||void 0})}async resize(e,t){const[{resize:r},{default:i}]=await Promise.all([import("../rest/networks/unitIdentifiers/resize.js"),import("../rest/networks/unitIdentifiers/support/ResizeParameters.js")]),s=new i({object:e,lastUnit:t});a(this.featureServiceUrl,this.gdbVersion||null)?(s.sessionId=l,await u(this.featureServiceUrl,this.gdbVersion,!0)):s.sessionId=null,s.gdbVersion=this.gdbVersion;const n=o(this.featureServiceUrl,null,this.gdbVersion,!1),d=await r(this.networkServiceUrl,s);n.resolve({edits:null,addedFeatures:[],updatedFeatures:[],deletedFeatures:[],addedAttachments:[],updatedAttachments:[],deletedAttachments:[],exceededTransferLimit:d.exceededTransferLimit,historicMoment:d.moment,editedFeatures:d.serviceEdits||void 0})}async query(e){const[{queryUnitIdentifiers:t},{default:r}]=await Promise.all([import("../rest/networks/unitIdentifiers/queryUnitIdentifiers.js"),import("../rest/networks/unitIdentifiers/support/QueryUnitIdentifiersParameters.js")]),i=new r({objects:e});i.gdbVersion=this.gdbVersion,i.moment=this.historicMoment;return await t(this.networkServiceUrl,i)}generateCombineNetworkElements(e){return{id:this._ensureSingleSourceIdAsValidLayerId(e),combineGroupedObjects:[{globalIds:e.map(e=>e.globalId)}]}}generateDivideNetworkElements(e,t){return{id:this._ensureSingleSourceIdAsValidLayerId([e]),divideGroupedObjects:[{globalId:e.globalId,numUnits:t}]}}_ensureSingleSourceIdAsValidLayerId(e){const i=t(e.map(e=>e.networkSourceId));if(i.length>1)throw new r("utility-network:invalid-source-id","'networkSourceId' is not valid. Ensure that all network elements have the same 'networkSourceId' and that it corresponds to a valid layer in the utility network.");const s=i[0],n=this.utilityNetwork.getLayerIdBySourceId(s);if(null==n)throw new r("utility-network:invalid-source-id","'networkSourceId' is not valid. Ensure that all network elements have the same 'networkSourceId' and that it corresponds to a valid layer in the utility network.");return n}};e([s({type:d,constructOnly:!0})],c.prototype,"utilityNetwork",void 0),e([s()],c.prototype,"networkServiceUrl",null),e([s()],c.prototype,"featureServiceUrl",null),e([s()],c.prototype,"gdbVersion",null),e([s()],c.prototype,"historicMoment",null),c=e([n("esri.networks.UnitIdentifierManager")],c);const m=c;export{m as default};
