{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://brimatt16219.github.io/l3lint/schemas/results.schema.json",
  "title": "l3lint results",
  "description": "The JSON output of l3lint lint. Findings are advisory: they say a payload is likely to downgrade or meets the documented requirement. Card networks and issuers decide the rate.",
  "type": "object",
  "additionalProperties": false,
  "required": ["tool", "rulePacks", "inputs", "transactions", "summary", "exitCode"],
  "properties": {
    "schemaVersion": { "const": "1.0", "description": "Results schema version." },
    "tool": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "version"],
      "description": "The tool that wrote the results.",
      "properties": {
        "name": { "type": "string", "description": "Always l3lint." },
        "version": { "type": "string", "description": "Engine version, for example 1.0.0." },
        "informationUri": { "type": "string", "description": "Project home page." }
      }
    },
    "rulePacks": {
      "type": "object",
      "description": "Rule pack ID to pack version.",
      "additionalProperties": { "type": "string" }
    },
    "asOf": { "$ref": "#/$defs/dateOrNull", "description": "The --as-of date when given, else null (each transaction then carries its own as-of date)." },
    "profile": { "type": "string", "description": "Processor profile used." },
    "inputs": {
      "type": "array",
      "description": "Every input of the run, in the order given.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["path", "format", "sha256", "transactions"],
        "properties": {
          "path": { "type": "string", "description": "The path as given (relative paths stay relative), or - for standard input." },
          "format": { "type": "string", "description": "The format the input was read as, for example stripe; unknown when it could not be read." },
          "sha256": { "type": "string", "minLength": 1, "description": "Lowercase hex SHA-256 of the input's bytes." },
          "transactions": { "type": "integer", "minimum": 0, "description": "How many transactions the input held." }
        }
      }
    },
    "inputErrors": {
      "type": "array",
      "description": "Inputs, or NDJSON records, that could not be read. Each one makes the exit code at least 2.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["path", "message"],
        "properties": {
          "path": { "type": "string", "description": "The input that failed." },
          "line": { "type": ["integer", "null"], "description": "The line where reading failed, when known." },
          "message": { "type": "string", "description": "What went wrong and what to change." },
          "candidates": { "type": "array", "items": { "type": "string" }, "description": "The formats that tied when detection could not choose; pass one with --format." }
        }
      }
    },
    "transactions": { "type": "array", "items": { "$ref": "#/$defs/transaction" }, "description": "One entry per transaction, in input order." },
    "batchFindings": { "type": "array", "items": { "$ref": "#/$defs/finding" }, "description": "Findings about the run as a whole, such as GEN-DQ-007. Each points at the first transaction that carries the repeated value." },
    "summary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["transactions", "errors", "warnings", "information", "byRule"],
      "description": "Counts over every finding, including findings left out by --max-findings.",
      "properties": {
        "transactions": { "type": "integer", "minimum": 0, "description": "Transactions linted." },
        "errors": { "type": "integer", "minimum": 0, "description": "Error findings." },
        "warnings": { "type": "integer", "minimum": 0, "description": "Warning findings." },
        "information": { "type": "integer", "minimum": 0, "description": "Information findings." },
        "byRule": { "type": "object", "additionalProperties": { "type": "integer", "minimum": 0 }, "description": "Rule ID to the number of findings it raised." },
        "byBrand": {
          "type": "object",
          "description": "Brand to finding counts. A general rule's findings count under the transaction's brand.",
          "additionalProperties": {
            "type": "object",
            "additionalProperties": false,
            "required": ["errors", "warnings", "information"],
            "properties": {
              "errors": { "type": "integer", "minimum": 0, "description": "Error findings for the brand." },
              "warnings": { "type": "integer", "minimum": 0, "description": "Warning findings for the brand." },
              "information": { "type": "integer", "minimum": 0, "description": "Information findings for the brand." }
            }
          }
        },
        "findingsShown": { "type": "integer", "minimum": 0, "description": "Findings written to the output. Present only when --max-findings left some out." },
        "findingsOmitted": { "type": "integer", "minimum": 0, "description": "Findings left out by --max-findings. Present only when above 0." }
      }
    },
    "notes": { "type": "array", "items": { "type": "string" }, "description": "Notes about the run, such as where the settings came from." },
    "exitCode": { "type": "integer", "minimum": 0, "maximum": 3, "description": "The exit code of the run: 0 clean or below --fail-on, 1 findings at or above --fail-on, 2 usage or input error, 3 rule pack, config or internal error." }
  },
  "$defs": {
    "dateOrNull": { "type": ["string", "null"], "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
    "brand": { "enum": ["visa", "mastercard", "amex", "discover", "unknown"] },
    "tierName": { "enum": ["product3", "product2", "belowProduct3", "belowProduct2", "dataRate3", "dataRate2", "dataRate1", "none"] },
    "tier": {
      "type": "object",
      "additionalProperties": false,
      "required": ["best", "likely", "status"],
      "description": "The tier rollup for one brand: the best tier the card and MCC allow and the tier the data likely reaches.",
      "properties": {
        "brand": { "$ref": "#/$defs/brand", "description": "The brand. Present in likelyTiers entries." },
        "best": { "$ref": "#/$defs/tierName", "description": "The best tier the card and MCC allow, or none." },
        "likely": { "$ref": "#/$defs/tierName", "description": "The tier the payload likely reaches." },
        "status": { "enum": ["meets", "atRisk", "blocked", "noBenefit"], "description": "meets: the payload meets the documented requirements of the best tier. atRisk: Visa may still reject the data after settlement. blocked: an error finding blocks the best tier. noBenefit: no enhanced-data rate exists for this card, brand or MCC." },
        "blockingErrors": { "type": "integer", "minimum": 0, "description": "How many error findings blocked tiers." }
      }
    },
    "transaction": {
      "type": "object",
      "additionalProperties": false,
      "required": ["index", "input", "findings"],
      "description": "The result for one transaction.",
      "properties": {
        "index": { "type": "integer", "minimum": 0, "description": "0-based position of the transaction in the run." },
        "input": { "type": "integer", "minimum": 0, "description": "0-based index of its input in inputs." },
        "id": { "type": ["string", "null"], "description": "The transaction ID from the payload." },
        "brand": { "$ref": "#/$defs/brand", "description": "The effective card brand: the --brand flag, else the payload, else the config file." },
        "brands": { "type": "array", "items": { "$ref": "#/$defs/brand" }, "description": "Every brand evaluated: one brand normally, all four with --brand all. Absent when the brand is unknown and only general rules ran." },
        "cardProduct": { "enum": ["consumer", "business", "corporate", "purchasing", "fleet", "commercialPrepaid", "unknown", null], "description": "The effective card product." },
        "mcc": { "type": ["string", "null"], "description": "The effective merchant category code." },
        "format": { "type": "string", "description": "The adapter that read the transaction, for example stripe." },
        "asOf": { "$ref": "#/$defs/dateOrNull", "description": "The date whose rules applied: --as-of, else transactionDate, else the day of the run." },
        "likelyTier": { "oneOf": [ { "$ref": "#/$defs/tier" }, { "type": "null" } ], "description": "The tier rollup for the transaction's brand, or null when the brand is unknown." },
        "likelyTiers": { "type": "array", "items": { "$ref": "#/$defs/tier" }, "description": "One tier rollup per evaluated brand. Present when more than one brand was evaluated." },
        "costEstimate": { "$ref": "#/$defs/costEstimate", "description": "Estimated cost from the user's rate table. Present only with --rates." },
        "notes": { "type": "array", "items": { "type": "string" }, "description": "Notes such as context overrides and adapter remarks." },
        "findings": { "type": "array", "items": { "$ref": "#/$defs/finding" }, "description": "The findings, sorted by canonical path, then rule ID." }
      }
    },
    "patchOperation": {
      "type": "object",
      "required": ["op", "path"],
      "description": "One RFC 6902 JSON Patch operation in the source format's paths and units.",
      "properties": {
        "op": { "enum": ["add", "remove", "replace", "move", "copy", "test"], "description": "The operation." },
        "path": { "type": "string", "description": "JSON Pointer of the target value in the source document." },
        "from": { "type": "string", "description": "JSON Pointer of the source value, for move and copy." },
        "value": { "description": "The value to add, replace or test." }
      }
    },
    "finding": {
      "type": "object",
      "additionalProperties": false,
      "required": ["ruleId", "severity", "impact", "path", "message", "fix", "confidence", "sources"],
      "description": "One rule result on one transaction.",
      "properties": {
        "ruleId": { "type": "string", "pattern": "^((GEN|VISA|MC|AMEX|DISC)-[A-Z0-9]+-[0-9]{3}|L3LINT-[A-Z]+-[0-9]{3})$", "description": "The rule ID, for example VISA-L3-004, or an engine diagnostic ID such as L3LINT-ENGINE-001." },
        "severity": { "enum": ["error", "warning", "information"], "description": "The effective severity after profile scoping and overrides." },
        "impact": { "enum": ["blocksLevel3", "blocksLevel2", "riskVisaValidation", "truncation", "noBenefit", "hygiene"], "description": "What the finding means for the interchange tier." },
        "brand": { "$ref": "#/$defs/brand", "description": "The brand whose pack raised the finding. Absent for general rules." },
        "transactionIndex": { "type": "integer", "minimum": 0, "description": "0-based index of the transaction. Present in batchFindings." },
        "path": {
          "type": "object",
          "additionalProperties": false,
          "required": ["canonical"],
          "description": "Where the problem is.",
          "properties": {
            "canonical": { "type": "string", "description": "JSON Pointer in the canonical payload, for example /lineItems/1/commodityCode." },
            "source": { "type": ["string", "null"], "description": "The same place in the original format, such as a Stripe JSON Pointer or a CSV cell label; null when the format has no such field." }
          }
        },
        "location": {
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["line", "column"],
              "properties": {
                "line": { "type": "integer", "minimum": 1, "description": "1-based line in the input file." },
                "column": { "type": "integer", "minimum": 1, "description": "1-based column in the input file." }
              }
            },
            { "type": "null" }
          ],
          "description": "Line and column of the value in the input file, or null when the value is absent or the position is unknown."
        },
        "message": { "type": "string", "description": "What is wrong, in plain words." },
        "expected": { "type": ["string", "null"], "description": "What the rule expected, when it can be stated." },
        "actual": { "type": ["string", "null"], "description": "The value found, already masked for card numbers; null when the value is absent." },
        "fix": { "type": "string", "description": "How to fix it, stated as an action." },
        "patch": { "oneOf": [ { "type": "array", "items": { "$ref": "#/$defs/patchOperation" } }, { "type": "null" } ], "description": "A mechanical RFC 6902 patch for this finding, or null when there is none." },
        "needsHuman": { "type": "boolean", "description": "True when a person must decide the fix, for example a proposed unit mapping. Absent otherwise." },
        "confidence": { "enum": ["public-brand", "processor-doc", "inferred", "policy"], "description": "The rule's confidence label." },
        "sources": { "type": "array", "items": { "type": "string" }, "description": "Public pages the rule comes from." }
      }
    },
    "costEstimate": {
      "type": "object",
      "additionalProperties": false,
      "required": ["label", "rateTable", "effective", "currency", "estimates"],
      "description": "Estimated interchange cost from the user's rate table. Always an estimate, never the actual fee.",
      "properties": {
        "label": { "const": "estimate", "description": "Always estimate." },
        "rateTable": { "type": "string", "description": "The rate table's name." },
        "effective": { "type": "string", "description": "The rate table's effective date." },
        "currency": { "type": "string", "description": "Currency of the amounts." },
        "estimates": {
          "type": "array",
          "description": "One entry per evaluated brand that has categories in the rate table.",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["brand", "likelyTier", "likelyCost", "bestTier", "bestCost", "difference"],
            "properties": {
              "brand": { "$ref": "#/$defs/brand", "description": "The brand." },
              "likelyTier": { "type": "string", "description": "The rate table tier used for the likely outcome." },
              "likelyCost": { "type": ["number", "null"], "description": "Estimated cost at the likely tier, or null when the table has no matching category." },
              "bestTier": { "type": "string", "description": "The rate table tier used for the best outcome." },
              "bestCost": { "type": ["number", "null"], "description": "Estimated cost at the best tier, or null when the table has no matching category." },
              "difference": { "type": ["number", "null"], "description": "Likely cost minus best cost, when both exist: what the downgrade likely costs." }
            }
          }
        }
      }
    }
  }
}
