// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
/*!
 * Adapted directly from negotiator at https://github.com/jshttp/negotiator/
 * which is licensed as follows:
 *
 * (The MIT License)
 *
 * Copyright (c) 2012-2014 Federico Romero
 * Copyright (c) 2012-2014 Isaac Z. Schlueter
 * Copyright (c) 2014-2015 Douglas Christopher Wilson
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * 'Software'), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

export interface Specificity {
  i: number;
  o?: number;
  q: number;
  s?: number;
}

export function compareSpecs(a: Specificity, b: Specificity): number {
  return (
    b.q - a.q ||
    (b.s ?? 0) - (a.s ?? 0) ||
    (a.o ?? 0) - (b.o ?? 0) ||
    a.i - b.i ||
    0
  );
}

export function isQuality(spec: Specificity): boolean {
  return spec.q > 0;
}

// denoCacheMetadata={"headers":{"access-control-allow-origin":"*","accept-ranges":"bytes","date":"Tue, 28 Jul 2026 12:31:15 GMT","x-robots-tag":"noindex","content-type":"text/typescript","server":"cloudflare","x-jsr-backend":"modules","age":"126790","content-length":"1801","etag":"\"4e19b0298228ec5b21aad54216132a77\"","cf-ray":"a223e6586c6e7db6-LAX","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=%2FCtEtzBItO8S6l4%2BTaqhIvPDj2XK39hJySrDaBHTAFr%2BAgVlyPxkgQf5nFggWyNH%2BCUsynnOBaYjgSnp7wKH%2BKL5AXENmtsKmnHD29skFzJnh1fFSOkKw8g%3D\"}]}","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","cache-control":"public, max-age=31536000, immutable","access-control-expose-headers":"*","cf-cache-status":"HIT","alt-svc":"h3=\":443\"; ma=86400","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=yu7A141yKKcJUVnaRvtVD7UiN_1iH2oxRQuHq0fP4_Q-1785241875.274045-1.0.1.1-zWyCtTtm9HcC8VipMOP9yDeJvqL2a3u9bt0jDQqr88xurFbM19Cs3a7MUO3MGJpiy9fZ52SHbs5p_8CoYODoa4luxg9PPRuZYZckE5O01YNpcj_dWNok6XYhMExhvGJd; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","cross-origin-resource-policy":"cross-origin","vary":"Origin","x-content-type-options":"nosniff"},"url":"https://jsr.io/@std/http/0.224.5/_negotiation/common.ts","time":1785241875}