/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../chunks/_rollupPluginBabelHelpers","../chunks/tslib.es6","../request","../core/JSONSupport","../core/Loadable","../core/accessorSupport/decorators/property","../core/arrayUtils","../core/has","../core/accessorSupport/ensureType","../core/accessorSupport/decorators/subclass","./support/typeUtils"],(function(e,t,o,r,s,n,i,a,u,c,l){"use strict";let p=function(t){function r(e){var r;return(r=t.call(this,e)||this).request=o,r}e._inheritsLoose(r,t);var s=r.prototype;return s.initialize=function(){},s.load=function(){var t=e._asyncToGenerator((function*(e){const t=this.layer.load(e).then((()=>this._initializeRulesTable()));return this.addResolvingPromise(t),this}));function o(e){return t.apply(this,arguments)}return o}(),s.getFeatureSQL=function(e,t){const o=e.layerId.toString(),r=e.fieldsIndex.normalizeFieldName("assetGroup"),s=e.fieldsIndex.normalizeFieldName("assetType"),n=t.attributes[r],i=t.attributes[s],a=this.rulesHash[o];if(a){const e=a.assetGroupHash[n];if(e){const t=e.assetTypeHash[i];return t||null}}return null},s._initializeRulesTable=function(){var t=e._asyncToGenerator((function*(){const e={};let t;!function(e){e[e.from=0]="from",e[e.to=1]="to",e[e.via=2]="via"}(t||(t={}));const o=[{networkSourceId:"fromNetworkSource",assetGroupId:"fromAssetGroup",assetTypeId:"fromAssetType"},{networkSourceId:"toNetworkSource",assetGroupId:"toAssetGroup",assetTypeId:"toAssetType"},{networkSourceId:"viaNetworkSource",assetGroupId:"viaAssetGroup",assetTypeId:"viaAssetType"}];for(const d of this.rules){if(d.ruleType!==l.RuleType.RTJunctionJunctionConnectivity&&d.ruleType!==l.RuleType.RTJunctionEdgeConnectivity&&d.ruleType!==l.RuleType.RTEdgeJunctionEdgeConnectivity)continue;let T=[[t.from,t.to],[t.to,t.from]];d.ruleType===l.RuleType.RTEdgeJunctionEdgeConnectivity&&(T=[[t.from,t.via],[t.via,t.from],[t.to,t.via],[t.via,t.to]]);for(const f of T){var r,s,n,i,a,u,c;const T=f.shift(),v=f.shift();let h=!1;switch(d.ruleType){case l.RuleType.RTEdgeJunctionEdgeConnectivity:h=T===t.from||T===t.to;break;case l.RuleType.RTJunctionEdgeConnectivity:h=T===t.to}const S=o[T],g=d[S.networkSourceId].layerId.toString(),I=null==(r=d[S.assetGroupId])||null==(s=r.assetGroupCode)?void 0:s.toString(),G=d[S.assetTypeId],R=null==G||null==(n=G.assetTypeCode)?void 0:n.toString(),x=o[v],_=d[x.networkSourceId].layerId.toString(),m=null==(i=d[x.assetGroupId])||null==(a=i.assetGroupCode)?void 0:a.toString(),H=d[x.assetTypeId],V=null==H||null==(u=H.assetTypeCode)?void 0:u.toString(),$=e[g]?e[g]:{assetGroupHash:{}};if(!(I&&R&&m&&V))continue;const k=$.assetGroupHash[I]?$.assetGroupHash[I]:{assetTypeHash:{}},C=k.assetTypeHash[R]?k.assetTypeHash[R]:{};if(C[_]=C[_]?C[_]:{},h){C[g]=C[g]?C[g]:{};const e=`(assetgroup = ${I} AND assettype = ${R})`;var p;if(C[g].anyVertex=C[g].anyVertex?`${C[g].anyVertex}`:`${e}`,"esriNECPEndVertex"===H.connectivityPolicy)C[g].endVertex=null!=(p=C[g])&&p.endVertex?`${C[g].endVertex}`:`${e}`}const E=`(assetgroup = ${m} AND assettype = ${V})`;var y;if(C[_].anyVertex=null!=(c=C[_])&&c.anyVertex?`${C[_].anyVertex} OR ${E}`:`${E}`,"esriNECPEndVertex"===H.connectivityPolicy)C[_].endVertex=null!=(y=C[_])&&y.endVertex?`${C[_].endVertex} OR ${E}`:`${E}`;k.assetTypeHash[R]=C,$.assetGroupHash[I]=k,e[g]=$}}this.rulesHash=e}));function o(){return t.apply(this,arguments)}return o}(),r}(r.JSONSupportMixin(s));t.__decorate([n.property({constructOnly:!0})],p.prototype,"layer",void 0),t.__decorate([n.property({constructOnly:!0})],p.prototype,"rules",void 0),t.__decorate([n.property()],p.prototype,"rulesHash",void 0),t.__decorate([n.property({constructOnly:!0})],p.prototype,"request",void 0),p=t.__decorate([c.subclass("esri.networks.RulesTable")],p);return p}));
