// 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.
// This module is browser compatible.

import type { Any, ArrayObject } from "./_utils.ts";

export type KindType = "sequence" | "scalar" | "mapping";
export type StyleVariant = "lowercase" | "uppercase" | "camelcase" | "decimal";
export type RepresentFn = (data: Any, style?: StyleVariant) => Any;

interface TypeOptions {
  kind: KindType;
  resolve?: (data: Any) => boolean;
  construct?: (data: string) => Any;
  instanceOf?: Any;
  predicate?: (data: Record<string, unknown>) => boolean;
  represent?: RepresentFn | ArrayObject<RepresentFn>;
  defaultStyle?: StyleVariant;
  styleAliases?: ArrayObject;
}

function checkTagFormat(tag: string): string {
  return tag;
}

export class Type {
  tag: string;
  kind: KindType | null = null;
  instanceOf: Any;
  predicate?: (data: Record<string, unknown>) => boolean;
  represent?: RepresentFn | ArrayObject<RepresentFn>;
  defaultStyle?: StyleVariant;
  styleAliases?: ArrayObject;
  loadKind?: KindType;

  constructor(tag: string, options?: TypeOptions) {
    this.tag = checkTagFormat(tag);
    if (options) {
      this.kind = options.kind;
      this.resolve = options.resolve || (() => true);
      this.construct = options.construct || ((data: Any): Any => data);
      this.instanceOf = options.instanceOf;
      this.predicate = options.predicate;
      this.represent = options.represent;
      this.defaultStyle = options.defaultStyle;
      this.styleAliases = options.styleAliases;
    }
  }
  resolve: (data?: Any) => boolean = (): boolean => true;
  construct: (data?: Any) => Any = (data): Any => data;
}

// denoCacheMetadata={"headers":{"vary":"Origin","cf-ray":"a223e656afd27db6-LAX","x-jsr-backend":"modules","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=tEqXEMbCE3v5iYGOba7BYJ1LFmgAeeeOlB0o.I_WvfQ-1785241874.9971685-1.0.1.1-6DUTN1uPdoAA.in1.3ToWNpC2LkgYc5N6W39kswaT3aZMCQPqRs732gUkdhZt326BRe1iTKS2oAI5eMiZftP4g_pqsLhmTfanBcw6_gBKSFmED3dYNM3oT2R37NzQu4i; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","x-content-type-options":"nosniff","access-control-expose-headers":"*","cf-cache-status":"HIT","cache-control":"public, max-age=31536000, immutable","accept-ranges":"bytes","access-control-allow-origin":"*","server":"cloudflare","age":"1700007","date":"Tue, 28 Jul 2026 12:31:15 GMT","cross-origin-resource-policy":"cross-origin","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=mB0havsRPWegeJyH3kb4TQ6OQ5SlpRaOIB2JaarCp42F5VsIsbu4hZancBRIkZQsWlGoZIhPNgp7KOBlba6KmJ3pgnioaS1AKGYJa9UhRjBbquRGjYBlKak%3D\"}]}","content-length":"1840","x-robots-tag":"noindex","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","content-type":"text/typescript","etag":"\"942b9b3cec94749e13995c0f86b4a028\"","alt-svc":"h3=\":443\"; ma=86400"},"url":"https://jsr.io/@std/yaml/0.224.3/type.ts","time":1785241875}