{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aips.kivanura.org/spec/aips/covp/0.1/aips-covp-0.1.schema.json",
  "title": "AIPS COVP Observation Set 0.1",
  "description": "Version-bound consumption, feedback, fitness and value-realization evidence for AIPS Products. COVP evidence does not assign Product Family, APT or risk tier.",
  "type": "object",
  "required": ["@context", "type", "observationSetId", "productId", "productVersion", "observationWindow", "currentness", "records"],
  "properties": {
    "@context": {},
    "type": {"const": "COVPObservationSet"},
    "observationSetId": {"type": "string", "minLength": 1},
    "productId": {"type": "string", "minLength": 1},
    "productVersion": {"type": "string", "minLength": 1},
    "aiprodRef": {"type": "string", "minLength": 1},
    "marketplaceListingRef": {"type": "string", "minLength": 1},
    "observationWindow": {"$ref": "#/$defs/ObservationWindow"},
    "currentness": {"$ref": "#/$defs/COVPCurrentness"},
    "records": {
      "type": "array",
      "minItems": 1,
      "items": {
        "oneOf": [
          {"$ref": "#/$defs/UsageObservation"},
          {"$ref": "#/$defs/ConsumerFeedback"},
          {"$ref": "#/$defs/FitnessAssessment"},
          {"$ref": "#/$defs/ValueRealization"},
          {"$ref": "#/$defs/IncidentSignal"}
        ]
      }
    }
  },
  "additionalProperties": false,
  "$defs": {
    "ObservationWindow": {
      "type": "object",
      "required": ["start", "end"],
      "properties": {
        "start": {"type": "string", "format": "date-time"},
        "end": {"type": "string", "format": "date-time"}
      },
      "additionalProperties": false
    },
    "COVPCurrentness": {
      "type": "object",
      "required": ["observationCurrentness", "fitnessCurrentness", "valueCurrentness"],
      "properties": {
        "observationCurrentness": {"enum": ["CURRENT", "STALE", "INSUFFICIENT"]},
        "fitnessCurrentness": {"enum": ["CURRENT", "STALE", "REASSESSMENT_REQUIRED", "INSUFFICIENT"]},
        "valueCurrentness": {"enum": ["CURRENT", "STALE", "INSUFFICIENT"]},
        "assuranceEscalation": {"type": "boolean"},
        "evaluatedAt": {"type": "string", "format": "date-time"}
      },
      "additionalProperties": false
    },
    "UsageObservation": {
      "type": "object",
      "required": ["type", "recordId", "observedAt", "metricName", "metricValue", "unit", "aggregation", "sourceRef"],
      "properties": {
        "type": {"const": "UsageObservation"},
        "recordId": {"type": "string", "minLength": 1},
        "observedAt": {"type": "string", "format": "date-time"},
        "metricName": {"type": "string", "minLength": 1},
        "metricValue": {"type": "number"},
        "unit": {"type": "string", "minLength": 1},
        "aggregation": {"enum": ["COUNT", "SUM", "AVERAGE", "RATE", "PERCENTILE", "OTHER"]},
        "consumerContextRef": {"type": "string"},
        "portRef": {"type": "string"},
        "sourceRef": {"type": "string", "minLength": 1}
      },
      "additionalProperties": false
    },
    "ConsumerFeedback": {
      "type": "object",
      "required": ["type", "recordId", "observedAt", "feedbackKind", "summary", "severity", "sourceRef"],
      "properties": {
        "type": {"const": "ConsumerFeedback"},
        "recordId": {"type": "string", "minLength": 1},
        "observedAt": {"type": "string", "format": "date-time"},
        "feedbackKind": {"enum": ["QUALITATIVE", "STRUCTURED", "COMPLAINT", "FEATURE_REQUEST", "ADVERSE_OUTCOME", "OTHER"]},
        "summary": {"type": "string", "minLength": 1},
        "severity": {"enum": ["INFORMATIVE", "LOW", "MEDIUM", "HIGH", "CRITICAL"]},
        "consumerContextRef": {"type": "string"},
        "intendedUseRef": {"type": "string"},
        "evidenceRefs": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
        "sourceRef": {"type": "string", "minLength": 1}
      },
      "additionalProperties": false
    },
    "FitnessAssessment": {
      "type": "object",
      "required": ["type", "recordId", "assessedAt", "intendedUseRef", "status", "assessmentBasis", "evidenceRefs", "currentness"],
      "properties": {
        "type": {"const": "FitnessAssessment"},
        "recordId": {"type": "string", "minLength": 1},
        "assessedAt": {"type": "string", "format": "date-time"},
        "intendedUseRef": {"type": "string", "minLength": 1},
        "consumerContextRef": {"type": "string"},
        "status": {"enum": ["FIT", "CONDITIONAL", "UNFIT", "INSUFFICIENT_EVIDENCE"]},
        "assessmentBasis": {"type": "string", "minLength": 1},
        "conditions": {"type": "array", "items": {"type": "string"}},
        "evidenceRefs": {"type": "array", "minItems": 1, "items": {"type": "string"}, "uniqueItems": true},
        "currentness": {"enum": ["CURRENT", "STALE", "REASSESSMENT_REQUIRED"]},
        "assessedBy": {"type": "string"}
      },
      "additionalProperties": false
    },
    "ValueRealization": {
      "type": "object",
      "required": ["type", "recordId", "observedAt", "valueCategory", "metricName", "observedValue", "unit", "attributionConfidence", "evidenceRefs"],
      "properties": {
        "type": {"const": "ValueRealization"},
        "recordId": {"type": "string", "minLength": 1},
        "observedAt": {"type": "string", "format": "date-time"},
        "valueCategory": {"enum": ["FINANCIAL", "OPERATIONAL", "RISK_REDUCTION", "CLIENT_VALUE", "QUALITY", "PRODUCTIVITY", "LEARNING", "OTHER"]},
        "metricName": {"type": "string", "minLength": 1},
        "observedValue": {"type": "number"},
        "baselineValue": {"type": "number"},
        "targetValue": {"type": "number"},
        "unit": {"type": "string", "minLength": 1},
        "attributionConfidence": {"enum": ["UNKNOWN", "LOW", "MEDIUM", "HIGH"]},
        "consumerContextRef": {"type": "string"},
        "evidenceRefs": {"type": "array", "minItems": 1, "items": {"type": "string"}, "uniqueItems": true}
      },
      "additionalProperties": false
    },
    "IncidentSignal": {
      "type": "object",
      "required": ["type", "recordId", "observedAt", "incidentRef", "severity", "summary", "assuranceEscalation"],
      "properties": {
        "type": {"const": "IncidentSignal"},
        "recordId": {"type": "string", "minLength": 1},
        "observedAt": {"type": "string", "format": "date-time"},
        "incidentRef": {"type": "string", "minLength": 1},
        "severity": {"enum": ["LOW", "MEDIUM", "HIGH", "CRITICAL"]},
        "summary": {"type": "string", "minLength": 1},
        "consumerContextRef": {"type": "string"},
        "assuranceEscalation": {"type": "boolean"}
      },
      "additionalProperties": false
    }
  }
}
