/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import n from"../Dictionary.js";import{ArcadeExecutionError as a}from"../executionError.js";import{B as e,k as t,T as r,s as o,m as i,a4 as c,X as s,K as d,V as u,a5 as m,U as f,a6 as l,J as y,t as v,W 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,n,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(n,"InvalidParameter",s)})},p.functions.subtypes=function(r,o){return p.standardFunctionAsync(r,o,async(c,u,m)=>{if(e(m,1,1,r,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(r,"InvalidParameter",o)})},p.functions.domainname=function(n,r){return p.standardFunctionAsync(n,r,async(s,d,f)=>{if(e(f,2,4,n,r),t(f[0]))return u(f[0],o(f[1]),f[2],void 0===f[3]?void 0:f[3]);if(i(f[0])){await f[0]._ensureLoaded();const n=c(o(f[1]),f[0],null,void 0===f[3]?void 0:f[3]);return m(n,f[2])}throw new a(n,"InvalidParameter",r)})},p.signatures.push({name:"domainname",min:2,max:4}),p.functions.domaincode=function(n,r){return p.standardFunctionAsync(n,r,async(s,d,u)=>{if(e(u,2,4,n,r),t(u[0]))return f(u[0],o(u[1]),u[2],void 0===u[3]?void 0:u[3]);if(i(u[0])){await u[0]._ensureLoaded();const n=c(o(u[1]),u[0],null,void 0===u[3]?void 0:u[3]);return l(n,u[2])}throw new a(n,"InvalidParameter",r)})},p.signatures.push({name:"domaincode",min:2,max:4}),p.functions.text=function(n,t){return p.standardFunctionAsync(n,t,async(r,o,c)=>{if(e(c,1,2,n,t),i(c[0])){const e=y(c[1],"");if(""===e)return c[0].castToText();if("schema"===e.toLowerCase())return c[0].convertToText("schema",r.abortSignal);if("featureset"===e.toLowerCase())return c[0].convertToText("featureset",r.abortSignal);throw new a(n,"InvalidParameter",t)}return v(c[0],c[1])})},p.functions.gdbversion=function(n,r){return p.standardFunctionAsync(n,r,async(o,c,s)=>{if(e(s,1,1,n,r),t(s[0]))return s[0].gdbVersion();if(i(s[0])){return(await s[0].load()).gdbVersion}throw new a(n,"InvalidParameter",r)})},p.functions.schema=function(r,o){return p.standardFunctionAsync(r,o,async(c,s,u)=>{if(e(u,1,1,r,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(r,"InvalidParameter",o)})})}export{T as registerFunctions};
