import { Schema } from 'effect';
const UUID_WITH_DASHES_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
const UUID_WITHOUT_DASHES_REGEX = /^[0-9a-f]{32}$/i;
export function normalizeGeoId(id) {
  return id.replaceAll('-', '').toLowerCase();
}
export function isGeoId(id) {
  if (UUID_WITHOUT_DASHES_REGEX.test(id)) return true;
  if (UUID_WITH_DASHES_REGEX.test(id)) return true;
  return UUID_WITHOUT_DASHES_REGEX.test(normalizeGeoId(id));
}
export function parseGeoId(id) {
  const normalized = normalizeGeoId(id);
  if (!UUID_WITHOUT_DASHES_REGEX.test(normalized)) {
    throw new Error(`Invalid Geo ID (expected UUID with or without dashes): ${id}`);
  }
  return normalized;
}
export function toUuid(id) {
  const normalized = parseGeoId(id);
  return [normalized.slice(0, 8), normalized.slice(8, 12), normalized.slice(12, 16), normalized.slice(16, 20), normalized.slice(20)].join('-');
}
/**
 * An Effect Schema that accepts UUIDs with or without dashes and always decodes/encodes
 * to the dashless (normalized) `GeoId` format.
 */
export const GeoIdSchema = /*#__PURE__*/Schema.transform(Schema.String, Schema.String, {
  strict: true,
  decode: value => parseGeoId(value),
  encode: value => parseGeoId(value)
}).pipe(/*#__PURE__*/Schema.annotations({
  identifier: 'GeoId'
}));
//# sourceMappingURL=geo-id.js.map