import Bluebird from"../../deps/bluebird_fork.js";import{validation}from"../../Validation.js";import{inline,schedulePromiseCancellation,fetch}from"./tools.js";class GetCodedValueDomain{execute(i,e){var n=validation.exists("layer",i.layer,void 0);let o=validation.exists("layerInfo",i.layerInfo,void 0);const a=validation.string("type",i.type,void 0),r=validation.string("field",i.field,void 0);var t=validation.string("url",i.url,void 0),l=validation.number("timeout",i.timeout,void 0);const d={};i.dynamicLayerDefinition?d.layer=i.dynamicLayerDefinition:i.source&&(d.layer={source:i.source}),o=o||n;l=t?fetch(t,d,l,e.cancellationToken.signal):Bluebird.resolve(o);function s(i){i=i.fields;if(i instanceof Array)for(const n of i)if(n.name===r){var e=n.domain;if(null!=e)if(e.codedValues instanceof Array)return{domain:e}}return{}}return schedulePromiseCancellation(e,l),inline(l,function(i){return null!=i?(void 0!==a?function(i){var e=i.types;if(e instanceof Array)for(const o of e)if(o.id===a){var n=o.domains;if(null!=n){n=n[r];if(null!=n){if(n.codedValues instanceof Array)return{domain:n};if("inherited"===n.type)return s(i)}}return{}}return{}}:s)(i):{}})}}GetCodedValueDomain.action="gcx:wf:arcgis::GetCodedValueDomain",GetCodedValueDomain.suite="gcx:wf:builtin";export{GetCodedValueDomain};