{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aicore.sk/schemas/audit-record/1.0.0/schema.json",
  "title": "AI CORE public assessment record 1.0.0",
  "description": "Structural validation only; not an audit verdict. Public free text requires separate privacy review.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "record_id",
    "record_kind",
    "profile_id",
    "profile_version",
    "control_id",
    "subject_snapshot",
    "assessment_window",
    "method",
    "result",
    "basis",
    "evidence",
    "limitations",
    "visibility"
  ],
  "properties": {
    "record_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 4000
    },
    "control_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 4000
    },
    "subject_snapshot": {
      "type": "string",
      "minLength": 1,
      "maxLength": 4000
    },
    "method": {
      "type": "string",
      "minLength": 1,
      "maxLength": 4000
    },
    "applicability_reason": {
      "type": "string",
      "minLength": 1,
      "maxLength": 4000
    },
    "evidence_access_note": {
      "type": "string",
      "minLength": 1,
      "maxLength": 4000
    },
    "supersedes": {
      "type": "string",
      "minLength": 1,
      "maxLength": 4000
    },
    "record_kind": {
      "enum": [
        "example",
        "assessment"
      ]
    },
    "profile_id": {
      "enum": [
        "https://aicore.sk/profiles/common/1.0.0/",
        "https://aicore.sk/profiles/aiindustry/1.0.0/",
        "https://aicore.sk/profiles/agents/1.0.0/"
      ]
    },
    "profile_version": {
      "const": "1.0.0"
    },
    "visibility": {
      "const": "public"
    },
    "result": {
      "enum": [
        "PASS",
        "FAIL",
        "NOT_TESTED",
        "NOT_APPLICABLE",
        "INCONCLUSIVE"
      ]
    },
    "basis": {
      "enum": [
        "operator_statement",
        "observed_test",
        "independent_assessment",
        "none"
      ]
    },
    "assessment_window": {
      "oneOf": [
        {
          "type": "null"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "start",
            "end"
          ],
          "properties": {
            "start": {
              "type": "string",
              "format": "date-time"
            },
            "end": {
              "type": "string",
              "format": "date-time"
            }
          }
        }
      ]
    },
    "limitations": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 2000
      },
      "maxItems": 30
    },
    "finding_severity": {
      "enum": [
        "informational",
        "low",
        "medium",
        "high",
        "critical",
        "not_assessed"
      ]
    },
    "remediation_status": {
      "enum": [
        "not_required",
        "open",
        "planned",
        "implemented",
        "verified"
      ]
    },
    "evidence": {
      "type": "array",
      "maxItems": 100,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "kind",
          "visibility",
          "description"
        ],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "kind": {
            "enum": [
              "statement",
              "test_receipt",
              "observation",
              "document",
              "assessment"
            ]
          },
          "visibility": {
            "enum": [
              "public",
              "restricted"
            ]
          },
          "description": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4000
          },
          "uri": {
            "type": "string",
            "format": "uri",
            "pattern": "^https://"
          },
          "sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "visibility": {
                  "const": "restricted"
                }
              }
            },
            "then": {
              "not": {
                "required": [
                  "uri"
                ]
              }
            }
          }
        ]
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "result": {
            "enum": [
              "PASS",
              "FAIL"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "assessment_window": {
            "type": "object"
          },
          "evidence": {
            "minItems": 1
          },
          "basis": {
            "enum": [
              "observed_test",
              "independent_assessment"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "result": {
            "const": "NOT_TESTED"
          }
        }
      },
      "then": {
        "properties": {
          "assessment_window": {
            "type": "null"
          },
          "evidence": {
            "maxItems": 0
          },
          "basis": {
            "const": "none"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "result": {
            "const": "NOT_APPLICABLE"
          }
        }
      },
      "then": {
        "required": [
          "applicability_reason"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "result": {
            "enum": [
              "PASS",
              "FAIL"
            ]
          },
          "basis": {
            "const": "observed_test"
          }
        }
      },
      "then": {
        "properties": {
          "evidence": {
            "contains": {
              "properties": {
                "kind": {
                  "enum": [
                    "observation",
                    "test_receipt"
                  ]
                }
              },
              "required": [
                "kind"
              ]
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "result": {
            "enum": [
              "PASS",
              "FAIL"
            ]
          },
          "basis": {
            "const": "independent_assessment"
          }
        }
      },
      "then": {
        "properties": {
          "evidence": {
            "contains": {
              "properties": {
                "kind": {
                  "const": "assessment"
                }
              },
              "required": [
                "kind"
              ]
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "profile_id": {
            "const": "https://aicore.sk/profiles/common/1.0.0/"
          }
        }
      },
      "then": {
        "properties": {
          "control_id": {
            "enum": [
              "AC-C01",
              "AC-C02",
              "AC-C03",
              "AC-C04",
              "AC-C05",
              "AC-C06",
              "AC-C07",
              "AC-C08",
              "AC-C09",
              "AC-C10",
              "AC-C11",
              "AC-C12"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "profile_id": {
            "const": "https://aicore.sk/profiles/aiindustry/1.0.0/"
          }
        }
      },
      "then": {
        "properties": {
          "control_id": {
            "enum": [
              "AC-C01",
              "AC-C02",
              "AC-C03",
              "AC-C04",
              "AC-C05",
              "AC-C06",
              "AC-C07",
              "AC-C08",
              "AC-C09",
              "AC-C10",
              "AC-C11",
              "AC-C12"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "profile_id": {
            "const": "https://aicore.sk/profiles/agents/1.0.0/"
          }
        }
      },
      "then": {
        "properties": {
          "control_id": {
            "enum": [
              "AC-C01",
              "AC-C02",
              "AC-C03",
              "AC-C04",
              "AC-C05",
              "AC-C06",
              "AC-C07",
              "AC-C08",
              "AC-C09",
              "AC-C10",
              "AC-C11",
              "AC-C12",
              "AC-A01",
              "AC-A02",
              "AC-A03",
              "AC-A04",
              "AC-A05",
              "AC-A06",
              "AC-A07",
              "AC-A08"
            ]
          }
        }
      }
    }
  ]
}
