// 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";

function resolveYamlNull(data: string): boolean {
  const max = data.length;

  return (
    (max === 1 && data === "~") ||
    (max === 4 && (data === "null" || data === "Null" || data === "NULL"))
  );
}

function constructYamlNull(): null {
  return null;
}

function isNull(object: unknown): object is null {
  return object === null;
}

export const nil = new Type("tag:yaml.org,2002:null", {
  construct: constructYamlNull,
  defaultStyle: "lowercase",
  kind: "scalar",
  predicate: isNull,
  represent: {
    canonical(): string {
      return "~";
    },
    lowercase(): string {
      return "null";
    },
    uppercase(): string {
      return "NULL";
    },
    camelcase(): string {
      return "Null";
    },
  },
  resolve: resolveYamlNull,
});

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