{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://any.health/contracts/encounter.lifecycle/1/response.schema.json",
  "title": "Encounter Lifecycle representative family response",
  "description": "Representative generalized response shape. This artifact is not a normative validator or compatibility promise.",
  "$comment": "The current production binding returns a customer-specific Salesforce claim payload. This schema describes platform direction only.",
  "x-any-maturity": "representative",
  "x-any-scope": "family",
  "type": "object",
  "required": ["contract", "operation", "request_id", "status", "observed_at", "result", "evidence", "provenance", "issues"],
  "properties": {
    "contract": { "const": "any/encounter.lifecycle@1" },
    "operation": { "const": "encounter.lifecycle.resolve" },
    "request_id": { "type": "string", "minLength": 1 },
    "status": { "enum": ["resolved", "partial", "unresolved", "failed"] },
    "observed_at": { "type": "string", "format": "date-time" },
    "result": {
      "type": "object",
      "required": ["care_event", "economics"],
      "properties": {
        "care_event": {
          "type": "object",
          "properties": {
            "event_ref": { "type": "string" },
            "period": {
              "type": "object",
              "properties": {
                "start": { "type": "string", "format": "date" },
                "end": { "type": "string", "format": "date" }
              }
            },
            "place": { "type": "object" },
            "participants": { "type": "array", "items": { "type": "object" } },
            "clinical_context": { "type": "object" },
            "services": { "type": "array", "items": { "type": "object" } }
          },
          "additionalProperties": true
        },
        "economics": {
          "type": "object",
          "properties": {
            "currency": { "type": "string" },
            "charged": { "type": ["string", "number", "null"] },
            "allowed": { "type": ["string", "number", "null"] },
            "paid": { "type": ["string", "number", "null"] },
            "patient_responsibility": { "type": ["string", "number", "null"] },
            "adjustments": { "type": "array", "items": { "type": "object" } }
          },
          "additionalProperties": true
        }
      },
      "additionalProperties": true
    },
    "evidence": { "type": "array", "items": { "$ref": "#/$defs/evidence" } },
    "provenance": { "type": "array", "items": { "$ref": "#/$defs/provenance" } },
    "issues": { "type": "array", "items": { "$ref": "#/$defs/issue" } }
  },
  "additionalProperties": true,
  "$defs": {
    "evidence": {
      "type": "object",
      "required": ["evidence_ref", "kind", "source_system", "source_ref", "observed_at"],
      "properties": {
        "evidence_ref": { "type": "string" },
        "kind": { "enum": ["document", "source_record", "transaction", "other"] },
        "source_system": { "type": "string" },
        "source_ref": { "type": "string" },
        "observed_at": { "type": "string", "format": "date-time" },
        "locator": { "type": "object" }
      },
      "additionalProperties": true
    },
    "provenance": {
      "type": "object",
      "required": ["path", "method", "evidence_refs"],
      "properties": {
        "path": { "type": "string" },
        "method": { "enum": ["extracted", "mapped", "derived"] },
        "evidence_refs": { "type": "array", "minItems": 1, "items": { "type": "string" } },
        "confidence": { "type": "number", "minimum": 0, "maximum": 1 },
        "derivation": { "type": "string" }
      },
      "additionalProperties": true
    },
    "issue": {
      "type": "object",
      "required": ["code", "severity"],
      "properties": {
        "code": { "type": "string" },
        "severity": { "enum": ["info", "warning", "error"] },
        "path": { "type": "string" },
        "message": { "type": "string" },
        "evidence_refs": { "type": "array", "items": { "type": "string" } }
      },
      "additionalProperties": true
    }
  }
}
