{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://evidence.vitatally.example/evidence/v1/manifest.schema.json",
  "title": "Vitatally EvidenceManifest v1",
  "description": "The exact JSON contract decoded by VitatallyCore.EvidenceManifest.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "catalogVersion", "generatedAt", "expiresAt", "sources", "rules"],
  "properties": {
    "schemaVersion": { "const": 1 },
    "catalogVersion": { "type": "integer", "minimum": 1 },
    "generatedAt": { "type": "string", "format": "date-time" },
    "expiresAt": { "type": "string", "format": "date-time" },
    "sources": {
      "type": "array",
      "items": { "$ref": "#/$defs/evidenceSource" }
    },
    "rules": {
      "type": "array",
      "items": { "$ref": "#/$defs/evidenceRule" }
    }
  },
  "$defs": {
    "localizedText": {
      "type": "object",
      "additionalProperties": false,
      "required": ["ko", "en"],
      "properties": {
        "ko": { "type": "string", "minLength": 1 },
        "en": { "type": "string", "minLength": 1 }
      }
    },
    "journalImpactFactor": {
      "type": "object",
      "additionalProperties": false,
      "required": ["value", "source", "year"],
      "properties": {
        "value": { "type": "number", "exclusiveMinimum": 0 },
        "source": { "type": "string", "minLength": 1 },
        "year": { "type": "integer", "minimum": 1900 }
      }
    },
    "evidenceSource": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "title", "studyType", "targetPopulation", "citation", "url", "publicationYear", "reviewedAt"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9]+(?:[.-][a-z0-9]+)*$" },
        "title": { "$ref": "#/$defs/localizedText" },
        "studyType": {
          "enum": ["guideline", "systematicReview", "metaAnalysis", "networkMetaAnalysis", "randomizedTrial", "cohortStudy", "other"]
        },
        "targetPopulation": { "$ref": "#/$defs/localizedText" },
        "journalOrPublisher": { "$ref": "#/$defs/localizedText" },
        "supportingDomains": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": { "enum": ["heart", "stroke", "hypertension", "type2Diabetes"] }
        },
        "citation": { "type": "string", "minLength": 1 },
        "doi": { "type": "string", "pattern": "^10\\.[0-9]{4,9}/.+$" },
        "url": { "type": "string", "format": "uri", "pattern": "^https://" },
        "publicationYear": { "type": "integer", "minimum": 1900 },
        "reviewedAt": { "type": "string", "format": "date-time" },
        "impactFactor": { "$ref": "#/$defs/journalImpactFactor" }
      }
    },
    "evidencePopulation": {
      "type": "object",
      "additionalProperties": false,
      "required": ["requiredSafetyFlags", "excludedSafetyFlags", "description", "sexCriterion", "reportedMetadata"],
      "properties": {
        "minimumAge": { "type": "integer", "minimum": 0 },
        "maximumAge": { "type": "integer", "minimum": 0 },
        "requiredSafetyFlags": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "enum": ["heartDiseaseHistory", "strokeHistory", "heartRateAffectingMedication", "arrhythmia", "pacemaker", "clinicianExerciseRestriction"]
          }
        },
        "excludedSafetyFlags": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "enum": ["heartDiseaseHistory", "strokeHistory", "heartRateAffectingMedication", "arrhythmia", "pacemaker", "clinicianExerciseRestriction"]
          }
        },
        "description": { "$ref": "#/$defs/localizedText" },
        "sexCriterion": { "enum": ["female", "male", "all", "unspecified"] },
        "reportedMetadata": { "$ref": "#/$defs/evidencePopulationReportedMetadata" }
      }
    },
    "evidenceReportedAge": {
      "type": "object",
      "additionalProperties": false,
      "minProperties": 1,
      "properties": {
        "minimumYears": { "type": "number", "minimum": 0 },
        "maximumYears": { "type": "number", "minimum": 0 },
        "meanYears": { "type": "number", "minimum": 0 },
        "medianYears": { "type": "number", "minimum": 0 }
      }
    },
    "evidencePopulationReportedMetadata": {
      "type": "object",
      "additionalProperties": false,
      "required": ["sex"],
      "properties": {
        "participantCount": { "type": "integer", "minimum": 1 },
        "age": { "$ref": "#/$defs/evidenceReportedAge" },
        "sex": { "enum": ["femaleOnly", "maleOnly", "mixed", "unspecified"] },
        "geography": { "$ref": "#/$defs/localizedText" },
        "baselineCondition": { "$ref": "#/$defs/localizedText" }
      }
    },
    "evidenceProtocol": {
      "type": "object",
      "additionalProperties": false,
      "required": ["minimumExposureWeeks", "permittedExerciseKinds", "permittedIntensities"],
      "properties": {
        "minimumExposureWeeks": { "type": "number", "minimum": 0 },
        "minimumWeeklyModerateEquivalentMinutes": { "type": "number", "minimum": 0 },
        "maximumWeeklyModerateEquivalentMinutes": { "type": "number", "minimum": 0 },
        "minimumAverageSessionsPerWeek": { "type": "number", "minimum": 0 },
        "permittedExerciseKinds": {
          "type": "array",
          "uniqueItems": true,
          "items": { "enum": ["walking", "cycling", "swimming", "aerobic", "strength", "balance", "other"] }
        },
        "permittedIntensities": {
          "type": "array",
          "uniqueItems": true,
          "items": { "enum": ["light", "moderate", "vigorous"] }
        }
      }
    },
    "evidenceEffect": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "estimate", "unit"],
      "properties": {
        "type": { "enum": ["relativeRisk", "hazardRatio", "oddsRatio", "meanDifference", "riskReductionPercent"] },
        "estimate": { "type": "number" },
        "lowerConfidenceBound": { "type": "number" },
        "upperConfidenceBound": { "type": "number" },
        "unit": { "type": "string", "minLength": 1, "pattern": "\\S" }
      },
      "allOf": [
        {
          "if": { "required": ["lowerConfidenceBound"] },
          "then": { "required": ["upperConfidenceBound"] }
        },
        {
          "if": { "required": ["upperConfidenceBound"] },
          "then": { "required": ["lowerConfidenceBound"] }
        },
        {
          "if": { "properties": { "type": { "enum": ["relativeRisk", "hazardRatio", "oddsRatio"] } } },
          "then": {
            "properties": {
              "estimate": { "type": "number", "exclusiveMinimum": 0 },
              "lowerConfidenceBound": { "type": "number", "exclusiveMinimum": 0 },
              "upperConfidenceBound": { "type": "number", "exclusiveMinimum": 0 }
            }
          }
        },
        {
          "if": { "properties": { "type": { "const": "riskReductionPercent" } } },
          "then": {
            "properties": {
              "estimate": { "type": "number", "minimum": 0, "maximum": 100 },
              "lowerConfidenceBound": { "type": "number", "minimum": 0, "maximum": 100 },
              "upperConfidenceBound": { "type": "number", "minimum": 0, "maximum": 100 }
            }
          }
        }
      ]
    },
    "doseResponseModel": {
      "type": "object",
      "additionalProperties": false,
      "required": ["doseUnit", "minimumDose", "maximumDose", "estimateCoefficients"],
      "properties": {
        "doseUnit": { "const": "moderateEquivalentMinutesPerWeek" },
        "minimumDose": { "type": "number", "minimum": 0 },
        "maximumDose": { "type": "number", "minimum": 0 },
        "estimateCoefficients": { "type": "array", "minItems": 1, "items": { "type": "number" } },
        "lowerBoundCoefficients": { "type": "array", "minItems": 1, "items": { "type": "number" } },
        "upperBoundCoefficients": { "type": "array", "minItems": 1, "items": { "type": "number" } }
      }
    },
    "evidenceFollowUpDuration": {
      "type": "object",
      "additionalProperties": false,
      "required": ["basis"],
      "properties": {
        "basis": { "enum": ["fixed", "mean", "median", "minimum", "range"] },
        "reportedYears": { "type": "number", "exclusiveMinimum": 0 },
        "lowerBoundYears": { "type": "number", "exclusiveMinimum": 0 },
        "upperBoundYears": { "type": "number", "exclusiveMinimum": 0 }
      },
      "oneOf": [
        {
          "properties": { "basis": { "enum": ["fixed", "mean", "median", "minimum"] } },
          "required": ["reportedYears"],
          "not": {
            "anyOf": [
              { "required": ["lowerBoundYears"] },
              { "required": ["upperBoundYears"] }
            ]
          }
        },
        {
          "properties": { "basis": { "const": "range" } },
          "required": ["lowerBoundYears", "upperBoundYears"],
          "not": { "required": ["reportedYears"] }
        }
      ]
    },
    "evidenceExerciseDoseDenominator": {
      "type": "object",
      "additionalProperties": false,
      "required": ["value", "unit"],
      "properties": {
        "value": { "type": "number", "exclusiveMinimum": 0 },
        "unit": { "const": "moderateEquivalentMinutesPerWeek" }
      }
    },
    "evidenceRule": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "sourceID",
        "domain",
        "population",
        "exerciseProtocol",
        "projectionKind",
        "reportedEffect",
        "evidenceLocation",
        "summary",
        "limitations",
        "recommendationTitle",
        "recommendationSummary",
        "recommendationPriority"
      ],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9]+(?:[.-][a-z0-9]+)*$" },
        "sourceID": { "type": "string", "pattern": "^[a-z0-9]+(?:[.-][a-z0-9]+)*$" },
        "domain": { "enum": ["heart", "stroke", "hypertension", "type2Diabetes"] },
        "population": { "$ref": "#/$defs/evidencePopulation" },
        "exerciseProtocol": { "$ref": "#/$defs/evidenceProtocol" },
        "projectionKind": { "enum": ["doseResponse", "categorical"] },
        "reportedEffect": { "$ref": "#/$defs/evidenceEffect" },
        "doseResponseModel": { "$ref": "#/$defs/doseResponseModel" },
        "followUpDuration": { "$ref": "#/$defs/evidenceFollowUpDuration" },
        "exerciseDoseDenominator": { "$ref": "#/$defs/evidenceExerciseDoseDenominator" },
        "evidenceLocation": { "type": "string", "minLength": 1 },
        "summary": { "$ref": "#/$defs/localizedText" },
        "limitations": { "$ref": "#/$defs/localizedText" },
        "recommendationTitle": { "$ref": "#/$defs/localizedText" },
        "recommendationSummary": { "$ref": "#/$defs/localizedText" },
        "recommendationPriority": { "enum": ["routine", "beneficial", "reviewWithClinician"] }
      },
      "allOf": [
        {
          "if": { "properties": { "projectionKind": { "const": "doseResponse" } } },
          "then": { "required": ["doseResponseModel"] },
          "else": { "not": { "required": ["doseResponseModel"] } }
        }
      ]
    }
  }
}
