/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{union as e}from"../../core/SetUtils.js";import{dateOnlyToDateTime as n,timeOnlyToDateTime as i,timestampOffsetToDateTime as t}from"../../support/dateUtils.js";const r=new Set(["integer","small-integer","long","big-integer","esriFieldTypeInteger","esriFieldTypeSmallInteger","esriFieldTypeLong","esriFieldTypeBigInteger"]);function l(e){return null!=e&&r.has(e.type)}function u(e){return null!=e&&("date-only"===e.type||"esriFieldTypeDateOnly"===e.type)}function a(e){return null!=e&&("timestamp-offset"===e.type||"esriFieldTypeTimestampOffset"===e.type)}function o(e){return null!=e&&("time-only"===e.type||"esriFieldTypeTimeOnly"===e.type)}const s=new Set([...["single","double"],...["esriFieldTypeSingle","esriFieldTypeDouble"]]),m=e(r,s);function d(e){return null!=e&&m.has(e.type)}function c(e){return null!=e&&("string"===e.type||"esriFieldTypeString"===e.type)}function p(e,n,i){const t=i??e?.domain;if(!t)return null;switch(t.type){case"range":{const{min:i,max:r}=y(e,t);if(null!=i&&+n<i||null!=r&&+n>r)return"domain-validation-error::value-out-of-range";break}case"coded-value":case"codedValue":if(null==t.codedValues||t.codedValues.every(e=>null==e||e.code!==n))return"domain-validation-error::invalid-coded-value"}return null}function y(e,n){const i=n??e?.domain;if(!i||"range"!==i.type)return;const t="range"in i?i.range[0]:i.minValue,r="range"in i?i.range[1]:i.maxValue,s=l(e);return u(e)||o(e)||a(e)?{...g(e,r,t),isInteger:s}:{min:null!=t&&"number"==typeof t?t:null,max:null!=r&&"number"==typeof r?r:null,rawMin:t,rawMax:r,isInteger:s}}function f(e,n){switch(n.type){case"range":{const{min:i,max:t}=y(e,n);return u(e)||o(e)||a(e)?!!i&&!!t:"number"==typeof i&&Number.isFinite(i)&&"number"==typeof t&&Number.isFinite(t)}case"codedValue":case"coded-value":{const i=typeof n.codedValues[0].code;if("string"===i&&c(e)||"number"===i&&d(e))return!0}}return!1}function g(e,r,l){return u(e)?{min:n(l)?.toMillis(),max:n(r)?.toMillis(),rawMin:l,rawMax:r}:o(e)?{min:i(l)?.toMillis(),max:i(r)?.toMillis(),rawMin:l,rawMax:r}:a(e)?{min:t(l)?.toMillis(),max:t(r)?.toMillis(),rawMin:l,rawMax:r}:{max:null,min:null}}export{g as dateTimeFieldValuesToNumericRange,y as getDomainRange,f as isDomainValidForField,p as validateDomainValue};
