{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://scrubmytext.com/schemas/trust-my-choice-quality-card.schema.json",
  "title": "TrustMyChoice quality card",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "card_id",
    "target",
    "task",
    "evidence",
    "dimensions",
    "confidence",
    "methodology_version",
    "generated_at",
    "status",
    "limitations"
  ],
  "properties": {
    "schema_version": { "const": "0.1" },
    "card_id": { "type": "string", "pattern": "^tmc_[a-f0-9]{40}$" },
    "target": {
      "type": "object",
      "additionalProperties": false,
      "required": ["target_id", "type", "provider_domain", "canonical_endpoint", "version"],
      "properties": {
        "target_id": { "type": "string", "pattern": "^target_[a-f0-9]{40}$" },
        "type": { "enum": ["mcp_server", "rest_api"] },
        "provider_domain": { "type": "string", "minLength": 1, "maxLength": 253 },
        "canonical_endpoint": { "type": "string", "format": "uri", "maxLength": 2048 },
        "version": { "type": "string", "minLength": 1, "maxLength": 120 },
        "interface_digest": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" }
      }
    },
    "task": {
      "type": "object",
      "additionalProperties": false,
      "required": ["category"],
      "properties": {
        "category": { "type": "string", "minLength": 1, "maxLength": 120 },
        "region": { "type": "string", "minLength": 2, "maxLength": 40 },
        "max_latency_ms": { "type": "integer", "minimum": 0 },
        "max_price_micros": { "type": "integer", "minimum": 0 },
        "minimum_evidence_class": { "enum": ["E0", "E1", "E2", "E3", "E4"] }
      }
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["total", "by_class", "independent_sources", "window_start", "window_end"],
      "properties": {
        "total": { "type": "integer", "minimum": 0 },
        "by_class": {
          "type": "object",
          "additionalProperties": false,
          "required": ["E0", "E1", "E2", "E3", "E4"],
          "properties": {
            "E0": { "type": "integer", "minimum": 0 },
            "E1": { "type": "integer", "minimum": 0 },
            "E2": { "type": "integer", "minimum": 0 },
            "E3": { "type": "integer", "minimum": 0 },
            "E4": { "type": "integer", "minimum": 0 }
          }
        },
        "independent_sources": { "type": "integer", "minimum": 0 },
        "window_start": { "type": "string", "format": "date-time" },
        "window_end": { "type": "string", "format": "date-time" }
      }
    },
    "dimensions": {
      "type": "object",
      "additionalProperties": false,
      "required": ["outcome_success", "reliability", "latency", "price_accuracy"],
      "properties": {
        "outcome_success": { "$ref": "#/$defs/dimension" },
        "reliability": { "$ref": "#/$defs/dimension" },
        "latency": { "$ref": "#/$defs/dimension" },
        "price_accuracy": { "$ref": "#/$defs/dimension" }
      }
    },
    "confidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "score", "sample_size", "independent_sources"],
      "properties": {
        "status": { "enum": ["insufficient_evidence", "low", "moderate", "high"] },
        "score": { "type": ["number", "null"], "minimum": 0, "maximum": 100 },
        "sample_size": { "type": "integer", "minimum": 0 },
        "independent_sources": { "type": "integer", "minimum": 0 }
      }
    },
    "methodology_version": { "type": "string", "minLength": 1, "maxLength": 40 },
    "generated_at": { "type": "string", "format": "date-time" },
    "status": { "enum": ["insufficient_evidence", "active", "under_correction", "under_appeal", "superseded"] },
    "correction_status": { "enum": ["none", "provider_response", "correction_pending", "corrected", "appeal_pending", "appeal_resolved"] },
    "limitations": {
      "type": "array",
      "minItems": 1,
      "maxItems": 20,
      "items": { "type": "string", "minLength": 1, "maxLength": 300 }
    }
  },
  "$defs": {
    "dimension": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "score", "sample_size"],
      "properties": {
        "status": { "enum": ["insufficient_evidence", "measured"] },
        "score": { "type": ["number", "null"], "minimum": 0, "maximum": 100 },
        "sample_size": { "type": "integer", "minimum": 0 },
        "median": { "type": ["number", "null"], "minimum": 0 },
        "p95": { "type": ["number", "null"], "minimum": 0 }
      }
    }
  }
}

