// Ported from js-yaml v3.13.1:
// https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import type { Type } from "../_type.ts";
import { isPlainObject } from "../_utils.ts";

function resolveYamlOmap(data: Record<string, unknown>[]): boolean {
  const objectKeys = new Set();
  for (const object of data) {
    if (!isPlainObject(object)) return false;
    const keys = Object.keys(object);
    if (keys.length !== 1) return false;
    for (const key of keys) {
      if (objectKeys.has(key)) return false;
      objectKeys.add(key);
    }
  }
  return true;
}

export const omap: Type<"sequence", Record<PropertyKey, unknown>[]> = {
  tag: "tag:yaml.org,2002:omap",
  kind: "sequence",
  resolve: resolveYamlOmap,
  construct(data) {
    return data;
  },
};

// denoCacheMetadata={"headers":{"server":"cloudflare","cache-control":"public, max-age=31536000, immutable","content-type":"text/typescript","vary":"Origin","cf-ray":"a223e6590e517db6-LAX","access-control-allow-origin":"*","access-control-expose-headers":"*","cross-origin-resource-policy":"cross-origin","x-robots-tag":"noindex","x-content-type-options":"nosniff","content-length":"941","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=OzljK4qeaRIapVqHuzlzIYRgHUB32Ke4Ta8jGmOatIIPPunfDQ31qNDL81ZWGkHsDWybqhzH4roFA%2BjfZNcl79IoxOkISADg74A%2ByyykuOyxtguyPmq%2FtWs%3D\"}]}","set-cookie":"__cf_bm=38VnjD71Xf4ykLtVnOsiSR6JrbtvYRYA9qcRVvdh67E-1785241875.3724098-1.0.1.1-5cXoALTuH2nYXf5KgjLHdQVTMy8lHbuZZDwLFp0ri1H8MgQ80AZq5GzCYIsV1lzsGto0wTx_Q3ob_ejpaa8CJj_py7Zdb8cW4WJsc91v2itPEhhXSlzTNilVQ1ui3hLQ; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","cf-cache-status":"HIT","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","x-jsr-backend":"modules","date":"Tue, 28 Jul 2026 12:31:15 GMT","alt-svc":"h3=\":443\"; ma=86400","etag":"\"039f0a52c507e68ac60f0bc2287ba782\"","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';","age":"3532745","accept-ranges":"bytes"},"url":"https://jsr.io/@std/yaml/1.0.5/_type/omap.ts","time":1785241875}