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

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

  return (
    (max === 4 && (data === "true" || data === "True" || data === "TRUE")) ||
    (max === 5 && (data === "false" || data === "False" || data === "FALSE"))
  );
}

function constructYamlBoolean(data: string): boolean {
  return data === "true" || data === "True" || data === "TRUE";
}

export const bool = new Type("tag:yaml.org,2002:bool", {
  construct: constructYamlBoolean,
  defaultStyle: "lowercase",
  kind: "scalar",
  predicate: isBoolean,
  represent: {
    lowercase(object: boolean): string {
      return object ? "true" : "false";
    },
    uppercase(object: boolean): string {
      return object ? "TRUE" : "FALSE";
    },
    camelcase(object: boolean): string {
      return object ? "True" : "False";
    },
  },
  resolve: resolveYamlBoolean,
});

// denoCacheMetadata={"headers":{"cf-ray":"a223e6589ce17db6-LAX","age":"654389","cache-control":"public, max-age=31536000, immutable","cross-origin-resource-policy":"cross-origin","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';","x-content-type-options":"nosniff","server":"cloudflare","set-cookie":"__cf_bm=I.8FmAe0uEO75DR7KzQZ_3j0it4yGh_qVpPM6VOt_Jo-1785241875.2970185-1.0.1.1-P4e3fD.rSN7K23Xtbi.2gCsavIIbyyzOD2ysTHaKZm2Q6tu0FRWZhWhDy1uln5k1yFVw0tkFKQTWp7TtJAeBnLDq9zvUCR3.Ah96pGzegK3YGrDuXfWiJASZBe_ptQnK; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=BFRH%2FI5eqPzxb3EhFo809Ra4szH1uLSx2tCrs3Sremd8YLffO620GFQdVSIoKrcb2EQEx39F4fFNLbQIOJc00UwM0vSQ8WPGJdqzYCt9Wtr737eL443kvZk%3D\"}]}","etag":"\"0de804ae1dadc8af2ca6b8d29e26d778\"","vary":"Origin","cf-cache-status":"HIT","alt-svc":"h3=\":443\"; ma=86400","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","accept-ranges":"bytes","content-type":"text/typescript","x-robots-tag":"noindex","x-jsr-backend":"modules","date":"Tue, 28 Jul 2026 12:31:15 GMT","access-control-allow-origin":"*","content-length":"1206"},"url":"https://jsr.io/@std/yaml/0.224.3/_type/bool.ts","time":1785241875}