/*
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","./ImmutableArray","../chunks/languageUtils","../geometry/Geometry"],(function(t,n,i,s){"use strict";function e(t,n=!1){if(null==t)return null;if(i.isNumber(t))return i.toNumber(t);if(i.isBoolean(t))return i.toBoolean(t);if(i.isString(t))return i.toString(t);if(i.isDate(t))return i.toDate(t);if(i.isArray(t)){const i=[];for(const s of t)i.push(e(s,n));return i}const s=new r;s.immutable=!1;for(const i of Object.keys(t)){const r=t[i];void 0!==r&&s.setField(i,e(r,n))}return s.immutable=n,s}let r=function(){function r(t){this.declaredClass="esri.arcade.Dictionary",this.attributes=null,this.plain=!1,this.immutable=!0,this.attributes=t instanceof r?t.attributes:null==t?{}:t}var o=r.prototype;return o.field=function(t){const n=t.toLowerCase(),i=this.attributes[t];if(void 0!==i)return i;for(const s in this.attributes)if(s.toLowerCase()===n)return this.attributes[s];throw new Error("Field not Found : "+t)},o.setField=function(t,n){if(this.immutable)throw new Error("Dictionary is Immutable");const i=t.toLowerCase();if(void 0===this.attributes[t]){for(const t in this.attributes)if(t.toLowerCase()===i)return void(this.attributes[t]=n);this.attributes[t]=n}else this.attributes[t]=n},o.hasField=function(t){const n=t.toLowerCase();if(void 0!==this.attributes[t])return!0;for(const i in this.attributes)if(i.toLowerCase()===n)return!0;return!1},o.keys=function(){let t=[];for(const n in this.attributes)t.push(n);return t=t.sort(),t},o.castToText=function(){let t="";for(const e in this.attributes){""!==t&&(t+=",");const r=this.attributes[e];null==r?t+=JSON.stringify(e)+":null":i.isBoolean(r)||i.isNumber(r)||i.isString(r)?t+=JSON.stringify(e)+":"+JSON.stringify(r):r instanceof s||r instanceof n||r instanceof Array?t+=JSON.stringify(e)+":"+i.toStringExplicit(r):r instanceof Date?t+=JSON.stringify(e)+":"+JSON.stringify(r):null!==r&&"object"==typeof r&&void 0!==r.castToText&&(t+=JSON.stringify(e)+":"+r.castToText())}return"{"+t+"}"},r.convertObjectToArcadeDictionary=function(t,n=!0){const i=new r;i.immutable=!1;for(const s in t){const n=t[s];void 0!==n&&i.setField(s.toString(),e(n))}return i.immutable=n,i},r.convertJsonToArcade=function(t,n=!1){return e(t,n)},o.castAsJson=function(t=null){const n={};for(let s in this.attributes){const e=this.attributes[s];void 0!==e&&(null!=t&&t.keyTranslate&&(s=t.keyTranslate(s)),n[s]=i.castAsJson(e,t))}return n},o.castDictionaryValueAsJsonAsync=function(){var n=t._asyncToGenerator((function*(t,n,s,e=null,r){const o=yield i.castAsJsonAsync(s,e,r);return t[n]=o,o}));function s(t,i,s){return n.apply(this,arguments)}return s}(),o.castAsJsonAsync=function(){var n=t._asyncToGenerator((function*(t=null,n=null){const e={},r=[];for(let o in this.attributes){const u=this.attributes[o];null!=n&&n.keyTranslate&&(o=n.keyTranslate(o)),void 0!==u&&(i.isSimpleType(u)||u instanceof s||u instanceof Date?e[o]=i.castAsJson(u,n):r.push(this.castDictionaryValueAsJsonAsync(e,o,u,t,n)))}return r.length>0&&(yield Promise.all(r)),e}));function e(){return n.apply(this,arguments)}return e}(),r}();return r}));
