// 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 } from "../type.ts";
import type { Any } from "../_utils.ts";

const { hasOwn } = Object;

function resolveYamlSet(data: Any): boolean {
  if (data === null) return true;

  for (const key in data) {
    if (hasOwn(data, key)) {
      if (data[key] !== null) return false;
    }
  }

  return true;
}

function constructYamlSet(data: string): Any {
  return data !== null ? data : {};
}

export const set = new Type("tag:yaml.org,2002:set", {
  construct: constructYamlSet,
  kind: "mapping",
  resolve: resolveYamlSet,
});

// denoCacheMetadata={"headers":{"set-cookie":"__cf_bm=1aNiX9a2DXVDS1YtpPnBut2.JOmH5G5Pa_j6Kr7RRMw-1785241875.3015907-1.0.1.1-iGssohAbPCdOayp70s41YxnptnkTIcgK7a7ZEr.ebIxj8K4BigewdRbjj6Q47p4sfswFColnzLXlXatRjY5yr2uvu27szM11vam1TXNpKUYwywiVBBHg62de3YTEGSjt; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","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';","server":"cloudflare","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","content-length":"806","x-robots-tag":"noindex","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=l9Of5naB98mcOVr%2BQiIsR8PXfSHz2mZsbETbCNvnczNX5q3qvdbLgsToc%2BDrJWPgkAue2%2BfFPXNUANyegH3MV7sB4z4ztkkTxkTfnnHJXQ5RapxdrZHsQnA%3D\"}]}","x-content-type-options":"nosniff","cf-ray":"a223e6589cfb7db6-LAX","cf-cache-status":"HIT","etag":"\"95740ec9d3bab1ab57787fcd86f5e5f4\"","access-control-expose-headers":"*","content-type":"text/typescript","age":"2357727","cache-control":"public, max-age=31536000, immutable","vary":"Origin","cross-origin-resource-policy":"cross-origin","alt-svc":"h3=\":443\"; ma=86400","accept-ranges":"bytes","access-control-allow-origin":"*","x-jsr-backend":"modules","date":"Tue, 28 Jul 2026 12:31:15 GMT"},"url":"https://jsr.io/@std/yaml/0.224.3/_type/set.ts","time":1785241875}