{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://mariuscomper.uk/politica-si-pachetul/schema/public-app-receipt-1.0.json",
  "title": "Public App Receipt 1.0",
  "description": "A claim-level record for one mobile-app release, one defined service journey, one device state and one test date.",
  "type": "object",
  "required": [
    "id", "is_calibration", "app", "owner", "journey", "device",
    "tested_at", "method_version", "audit_level", "headline", "verdict",
    "states", "destinations", "claims", "repairs", "limitations"
  ],
  "properties": {
    "id": {"type": "string", "pattern": "^[a-z0-9][a-z0-9-]+$"},
    "slug": {"type": "string", "pattern": "^[a-z0-9][a-z0-9-]+$"},
    "is_calibration": {"type": "boolean"},
    "app": {
      "type": "object",
      "required": ["name", "package_id", "version", "apk_sha256"],
      "properties": {
        "name": {"type": "string", "minLength": 1},
        "package_id": {"type": "string", "minLength": 3},
        "version": {"type": "string", "minLength": 1},
        "apk_sha256": {"type": "string", "pattern": "^[a-fA-F0-9]{64}$"}
      },
      "additionalProperties": true
    },
    "owner": {"type": "string", "minLength": 1},
    "supplier": {"type": ["string", "null"]},
    "journey": {"$ref": "#/$defs/bilingual"},
    "device": {
      "type": "object",
      "required": ["model", "os", "locale", "lane"],
      "properties": {
        "model": {"type": "string"},
        "os": {"type": "string"},
        "locale": {"type": "string"},
        "lane": {"type": "string", "enum": ["stock", "instrumented", "stock + instrumented", "other"]}
      },
      "additionalProperties": true
    },
    "tested_at": {"type": "string", "format": "date-time"},
    "method_version": {"type": "string"},
    "audit_level": {"type": "string", "enum": ["R0", "R1", "R2", "CAL"]},
    "headline": {"$ref": "#/$defs/bilingual"},
    "dek": {"$ref": "#/$defs/bilingual"},
    "verdict": {
      "type": "string",
      "enum": [
        "declared_and_observed",
        "declared_not_observed_in_tested_journeys",
        "observed_not_clearly_described",
        "store_policy_differ",
        "destination_identified_fields_unknown",
        "insufficient_evidence",
        "repair_verified"
      ]
    },
    "states": {
      "type": "array",
      "minItems": 1,
      "items": {"$ref": "#/$defs/state"}
    },
    "destinations": {
      "type": "array",
      "items": {"$ref": "#/$defs/destination"}
    },
    "claims": {
      "type": "array",
      "items": {"$ref": "#/$defs/claim"}
    },
    "repairs": {
      "type": "array",
      "items": {"$ref": "#/$defs/repair"}
    },
    "limitations": {
      "type": "object",
      "required": ["ro", "en"],
      "properties": {
        "ro": {"type": "array", "items": {"type": "string"}},
        "en": {"type": "array", "items": {"type": "string"}}
      },
      "additionalProperties": false
    },
    "responses": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["party", "received_at", "summary"],
        "properties": {
          "party": {"type": "string"},
          "received_at": {"type": "string", "format": "date-time"},
          "summary": {"$ref": "#/$defs/bilingual"},
          "claim_ids": {"type": "array", "items": {"type": "string"}},
          "full_response_url": {"type": ["string", "null"], "format": "uri"}
        }
      }
    }
  },
  "$defs": {
    "bilingual": {
      "type": "object",
      "required": ["ro", "en"],
      "properties": {
        "ro": {"type": ["string", "array"]},
        "en": {"type": ["string", "array"]}
      },
      "additionalProperties": false
    },
    "state": {
      "type": "object",
      "required": ["id", "label", "service_result", "events"],
      "properties": {
        "id": {"type": "string"},
        "label": {"$ref": "#/$defs/bilingual"},
        "service_result": {"$ref": "#/$defs/bilingual"},
        "events": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["moment", "policy", "store", "device", "evidence_strength", "limitations", "domains"],
            "properties": {
              "moment": {"type": "string"},
              "policy": {"$ref": "#/$defs/bilingual"},
              "store": {"$ref": "#/$defs/bilingual"},
              "device": {"$ref": "#/$defs/bilingual"},
              "evidence_strength": {"type": "string"},
              "limitations": {"$ref": "#/$defs/bilingual"},
              "domains": {"type": "array", "items": {"type": "string"}}
            }
          }
        }
      }
    },
    "destination": {
      "type": "object",
      "required": ["domain", "owner", "role", "relationship", "first_seen", "states_seen", "payload_evidence", "payload_summary", "attribution_certainty"],
      "properties": {
        "domain": {"type": "string"},
        "owner": {"type": "string"},
        "role": {"$ref": "#/$defs/bilingual"},
        "relationship": {"type": "string", "enum": ["first_party", "processor", "third_party", "unresolved", "platform_service"]},
        "first_seen": {"type": "string"},
        "states_seen": {"type": "array", "items": {"type": "string"}},
        "payload_evidence": {"type": "string", "enum": ["connection_only", "metadata_only", "readable_data_category", "exact_synthetic_token", "encrypted_unknown"]},
        "payload_summary": {"$ref": "#/$defs/bilingual"},
        "attribution_certainty": {"type": "string", "enum": ["documented", "confirmed", "observed", "inferred", "unresolved", "disputed"]}
      }
    },
    "claim": {
      "type": "object",
      "required": ["id", "classification", "statement", "maximum_wording", "status"],
      "properties": {
        "id": {"type": "string"},
        "classification": {"type": "string"},
        "statement": {"$ref": "#/$defs/bilingual"},
        "maximum_wording": {"$ref": "#/$defs/bilingual"},
        "status": {"type": "string", "enum": ["draft", "sent_for_response", "published", "disputed", "superseded", "verified", "calibration"]},
        "evidence_artifact_ids": {"type": "array", "items": {"type": "string"}}
      }
    },
    "repair": {
      "type": "object",
      "required": ["id", "actor", "minimum_change", "verification", "status"],
      "properties": {
        "id": {"type": "string"},
        "actor": {"type": "string"},
        "minimum_change": {"$ref": "#/$defs/bilingual"},
        "verification": {"$ref": "#/$defs/bilingual"},
        "status": {"type": "string", "enum": ["proposed", "acknowledged", "promised", "updated", "retest_due", "verified", "disputed", "no_response", "superseded"]},
        "verified_at": {"type": "string", "format": "date"}
      }
    }
  },
  "additionalProperties": true
}
