{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://earswet.com/docs/schemas/earswet-evaluation-request.schema.json",
  "title": "Earswet Evaluation Request - Canonical Nested Contract",
  "type": "object",
  "required": ["oemSensorPayload"],
  "properties": {
    "persistEvidence": { "type": "boolean" },
    "oemSensorPayload": {
      "type": "object",
      "required": [
        "sensorVendorId",
        "sensorId",
        "markerId",
        "candidateValuePresence",
        "unit",
        "samplingTime",
        "calibrationVersion"
      ],
      "properties": {
        "sensorVendorId": { "type": "string", "minLength": 2 },
        "sensorId": { "type": "string", "minLength": 2 },
        "firmwareVersion": { "type": "string" },
        "markerId": {
          "type": "string",
          "enum": ["cortisol", "uric_acid", "lactate", "glucose", "sodium", "chloride", "potassium", "ph", "alcohol", "medication_metabolite"]
        },
        "candidateValuePresence": { "type": "boolean" },
        "candidateValue": { "type": ["number", "null"] },
        "unit": { "type": "string", "minLength": 1 },
        "samplingTime": { "type": "string", "format": "date-time" },
        "calibrationVersion": { "type": "string", "minLength": 1 },
        "sensorQualityFlag": { "type": "string", "enum": ["ok", "warning", "invalid", "unknown"] },
        "rawAccessPolicy": { "type": "string", "enum": ["deny", "allow_by_contract", "trend_only", "not_declared"] },
        "adapterIntegrity": { "type": "string", "enum": ["verified", "unverified", "failed"] }
      },
      "additionalProperties": true
    },
    "sweatQualityFrame": {
      "type": "object",
      "properties": {
        "sweatRateState": { "type": "string", "enum": ["stable", "unstable", "insufficient", "excessive", "unknown"] },
        "fillState": { "type": "string", "enum": ["fill_valid", "underfilled", "bubble_detected", "overflow", "unknown"] },
        "contaminationState": { "type": "string", "enum": ["clean", "contamination_suspected", "contamination_blocked", "unknown"] },
        "calibrationState": { "type": "string", "enum": ["valid", "expired", "incompatible", "unknown"] },
        "driftState": { "type": "string", "enum": ["stable", "drift_warning", "drift_invalid", "unknown"] },
        "reagentAgeState": { "type": "string", "enum": ["valid", "aging", "expired", "unknown"] },
        "skinTemperatureState": { "type": "string", "enum": ["normal", "elevated", "low", "unstable", "unknown"] },
        "ambientState": { "type": "string", "enum": ["normal", "hot_humid", "cold_dry", "unstable", "unknown"] },
        "framePresent": { "type": "boolean" }
      },
      "additionalProperties": true
    },
    "deviceEventFrame": {
      "type": "object",
      "properties": {
        "framePresent": { "type": "boolean" },
        "events": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["eventType", "occurredAt"],
            "properties": {
              "eventType": {
                "type": "string",
                "enum": ["ble_burst", "haptic_event", "adc_sampling_conflict", "battery_thermal", "charging_transition", "cpu_mcu_load_spike", "firmware_update", "app_api_request_storm", "frame_movement", "power_management"]
              },
              "occurredAt": { "type": "string", "format": "date-time" },
              "durationMs": { "type": "integer", "minimum": 0 },
              "intensity": { "type": "string", "enum": ["low", "medium", "high", "critical"] },
              "eventSource": { "type": "string", "enum": ["firmware", "mcu", "ble", "mobile_app", "server_api", "power", "sensor", "unknown"] },
              "trust": { "type": "string", "enum": ["verified", "unverified"] }
            },
            "additionalProperties": true
          }
        }
      },
      "additionalProperties": true
    },
    "outputRequest": {
      "type": "object",
      "properties": {
        "channel": { "type": "string", "enum": ["mobile_sdk", "ble", "server_api", "cloud_api", "external_api", "firmware_api", "verification_surface"] },
        "requestedMode": { "type": "string", "enum": ["actual_value", "limited", "trend", "status_only"] },
        "responseSchemaVersion": { "type": "string" },
        "consumerId": { "type": "string" },
        "purpose": { "type": "string", "enum": ["verification", "partner_sdk", "firmware", "consumer_app", "audit"] }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": true
}
