{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://platoskallipolis.com/schemas/resource-quality.v1.json",
  "title": "Plato's Kallipolis Production Resource Quality Record",
  "description": "Quality gate for a structured information resource before it can count as production supply.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "id",
    "version",
    "title",
    "summary",
    "content",
    "language",
    "category",
    "state",
    "canonicalUrl",
    "contentHash",
    "owner",
    "access",
    "provenance",
    "observedAt",
    "freshness",
    "license",
    "evidence"
  ],
  "properties": {
    "schema": {
      "const": "kallipolis.resource-quality.v1"
    },
    "id": {
      "type": "string",
      "pattern": "^resource\\.[a-z0-9]+(?:[.-][a-z0-9]+)*$",
      "maxLength": 160
    },
    "version": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
    },
    "title": {
      "type": "string",
      "minLength": 3,
      "maxLength": 160
    },
    "summary": {
      "type": "string",
      "minLength": 20,
      "maxLength": 1000
    },
    "content": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "facts"],
      "properties": {
        "kind": {
          "enum": ["protocol-overview", "specification-profile", "implementation-checklist", "connector-boundary", "infrastructure-boundary", "public-data-api-boundary", "evidence-index"]
        },
        "facts": {
          "type": "array",
          "minItems": 2,
          "maxItems": 50,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["id", "statement", "normativeLevel", "sourceIds"],
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^fact\\.[a-z0-9]+(?:[.-][a-z0-9]+)*$"
              },
              "statement": {
                "type": "string",
                "minLength": 10,
                "maxLength": 500
              },
              "normativeLevel": {
                "enum": ["normative", "informative"]
              },
              "sourceIds": {
                "type": "array",
                "minItems": 1,
                "uniqueItems": true,
                "items": {
                  "type": "string",
                  "pattern": "^source\\.[a-z0-9]+(?:[.-][a-z0-9]+)*$"
                }
              }
            }
          }
        }
      }
    },
    "language": {
      "type": "string",
      "pattern": "^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$"
    },
    "category": {
      "enum": [
        "agent-interoperability",
        "ai-discovery-and-registry",
        "ai-safety-provenance-and-audit",
        "platform-integration",
        "enterprise-application-connector",
        "data-knowledge-infrastructure",
        "public-data-api",
        "community-infrastructure"
      ]
    },
    "state": {
      "enum": ["prepared", "live", "retired"]
    },
    "canonicalUrl": {
      "type": "string",
      "format": "uri"
    },
    "contentHash": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "owner": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "type", "accountabilityUrl"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:[.-][a-z0-9]+)*$"
        },
        "name": {
          "type": "string",
          "minLength": 2,
          "maxLength": 160
        },
        "type": {
          "enum": ["organization", "individual", "public-body", "standards-body"]
        },
        "accountabilityUrl": {
          "type": "string",
          "format": "uri"
        }
      }
    },
    "access": {
      "type": "object",
      "additionalProperties": false,
      "required": ["mode", "url", "authentication", "robotsAllowed"],
      "properties": {
        "mode": {
          "enum": ["public", "authenticated", "organization"]
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "authentication": {
          "enum": ["none", "api-key", "oauth2", "enterprise-sso"]
        },
        "robotsAllowed": {
          "type": "boolean"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": { "mode": { "const": "public" } },
            "required": ["mode"]
          },
          "then": {
            "properties": { "authentication": { "const": "none" } }
          }
        }
      ]
    },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "required": ["method", "sources"],
      "properties": {
        "method": {
          "enum": ["primary-source", "official-specification", "regulatory-record", "peer-reviewed", "publisher-declared"]
        },
        "sources": {
          "type": "array",
          "minItems": 1,
          "maxItems": 50,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["id", "url", "title", "publisher", "observedAt"],
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^source\\.[a-z0-9]+(?:[.-][a-z0-9]+)*$"
              },
              "url": {
                "type": "string",
                "format": "uri"
              },
              "title": {
                "type": "string",
                "minLength": 3,
                "maxLength": 300
              },
              "publisher": {
                "type": "string",
                "minLength": 2,
                "maxLength": 160
              },
              "observedAt": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        }
      }
    },
    "observedAt": {
      "type": "string",
      "format": "date-time"
    },
    "freshness": {
      "type": "object",
      "additionalProperties": false,
      "required": ["policy", "state", "nextReviewAt"],
      "properties": {
        "policy": {
          "enum": ["max-age", "point-in-time", "version-bound"]
        },
        "state": {
          "enum": ["current", "stale", "unknown"]
        },
        "maxAgeSeconds": {
          "type": "integer",
          "minimum": 60,
          "maximum": 31536000
        },
        "nextReviewAt": {
          "type": "string",
          "format": "date-time"
        },
        "sourceVersion": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        }
      },
      "allOf": [
        {
          "if": {
            "properties": { "policy": { "const": "max-age" } },
            "required": ["policy"]
          },
          "then": { "required": ["maxAgeSeconds"] }
        },
        {
          "if": {
            "properties": { "policy": { "const": "version-bound" } },
            "required": ["policy"]
          },
          "then": { "required": ["sourceVersion"] }
        }
      ]
    },
    "license": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "url", "redistributionAllowed"],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "redistributionAllowed": {
          "type": "boolean"
        }
      }
    },
    "evidence": {
      "type": "array",
      "minItems": 1,
      "maxItems": 100,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "type", "url", "observedAt"],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^evidence\\.[a-z0-9]+(?:[.-][a-z0-9]+)*$"
          },
          "type": {
            "enum": ["source-claim", "schema-validation", "live-fetch", "integration-test", "independent-confirmation"]
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "observedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  }
}
