/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import n from"../Dictionary.js";import{ArcadeExecutionError as a}from"../executionError.js";import{B as e,k as t,X as r,s as o,m as i,a6 as c,$ as s,P as d,Z as u,a7 as m,Y as f,a8 as l,O as y,t as v,_ as w}from"../../chunks/languageUtils.js";import{layerFieldEsriConstants as p}from"../featureset/support/shared.js";function h(a,e){return a&&a.domain?"coded-value"===a.domain.type||"codedValue"===a.domain.type?n.convertObjectToArcadeDictionary({type:"codedValue",name:a.domain.name,dataType:p[a.field.type],codedValues:a.domain.codedValues.map(n=>({name:n.name,code:n.code}))},d(e)):n.convertObjectToArcadeDictionary({type:"range",name:a.domain.name,dataType:p[a.field.type],min:a.domain.minValue,max:a.domain.maxValue},d(e)):null}function T(p){"async"===p.mode&&(p.functions.domain=function(n,s){return p.standardFunctionAsync(n,s,async(d,u,m)=>{if(e(m,2,3,s),t(m[0])){return h(r(m[0],o(m[1]),void 0===m[2]?void 0:m[2]),n)}if(i(m[0])){await m[0]._ensureLoaded();return h(c(o(m[1]),m[0],null,void 0===m[2]?void 0:m[2]),n)}throw new a("InvalidParameter",s)})},p.functions.subtypes=function(r,o){return p.standardFunctionAsync(r,o,async(c,u,m)=>{if(e(m,1,1,o),t(m[0])){const a=s(m[0]);return a?n.convertObjectToArcadeDictionary(a,d(r)):null}if(i(m[0])){await m[0]._ensureLoaded();const a=m[0].subtypeMetadata();return a?n.convertObjectToArcadeDictionary(a,d(r)):null}throw new a("InvalidParameter",o)})},p.functions.domainname=function(n,r){return p.standardFunctionAsync(n,r,async(n,s,d)=>{if(e(d,2,4,r),t(d[0]))return u(d[0],o(d[1]),d[2],void 0===d[3]?void 0:d[3]);if(i(d[0])){await d[0]._ensureLoaded();const n=c(o(d[1]),d[0],null,void 0===d[3]?void 0:d[3]);return m(n,d[2])}throw new a("InvalidParameter",r)})},p.signatures.push({name:"domainname",min:2,max:4}),p.functions.domaincode=function(n,r){return p.standardFunctionAsync(n,r,async(n,s,d)=>{if(e(d,2,4,r),t(d[0]))return f(d[0],o(d[1]),d[2],void 0===d[3]?void 0:d[3]);if(i(d[0])){await d[0]._ensureLoaded();const n=c(o(d[1]),d[0],null,void 0===d[3]?void 0:d[3]);return l(n,d[2])}throw new a("InvalidParameter",r)})},p.signatures.push({name:"domaincode",min:2,max:4}),p.functions.text=function(n,t){return p.standardFunctionAsync(n,t,async(n,r,o)=>{if(e(o,1,2,t),i(o[0])){const e=y(o[1],"");if(""===e)return o[0].castToText();if("schema"===e.toLowerCase())return o[0].convertToText("schema",n.abortSignal);if("featureset"===e.toLowerCase())return o[0].convertToText("featureset",n.abortSignal);throw new a("InvalidParameter",t)}return v(o[0],o[1])})},p.functions.gdbversion=function(n,r){return p.standardFunctionAsync(n,r,async(n,o,c)=>{if(e(c,1,1,r),t(c[0]))return c[0].gdbVersion();if(i(c[0])){return(await c[0].load()).gdbVersion}throw new a("InvalidParameter",r)})},p.functions.schema=function(r,o){return p.standardFunctionAsync(r,o,async(c,s,u)=>{if(e(u,1,1,o),i(u[0]))return await u[0].load(),n.convertObjectToArcadeDictionary(u[0].schema(),d(r));if(t(u[0])){const a=w(u[0]);return a?n.convertObjectToArcadeDictionary(a,d(r)):null}throw new a("InvalidParameter",o)})})}export{T as registerFunctions};
