{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://commonworld.net/contracts/commonworld/commons-basis.schema.json",
  "title": "Commonworld Commons Basis",
  "description": "Structured, source-bound editorial justification for treating a catalog record as a Common or Commons infrastructure.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "kind",
    "project_id",
    "classification",
    "decision",
    "reviewed_at",
    "reviewer",
    "criteria",
    "confidence",
    "limitations"
  ],
  "properties": {
    "schema_version": {
      "type": "integer",
      "const": 1
    },
    "kind": {
      "type": "string",
      "const": "commonworld_commons_basis"
    },
    "project_id": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9-]{2,95}$"
    },
    "classification": {
      "type": "string",
      "enum": [
        "common",
        "commons-infrastructure",
        "undetermined"
      ]
    },
    "decision": {
      "type": "string",
      "enum": [
        "include",
        "needs_information",
        "reject"
      ]
    },
    "reviewed_at": {
      "type": "string",
      "format": "date"
    },
    "reviewer": {
      "type": "string",
      "minLength": 2,
      "maxLength": 120
    },
    "criteria": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "shared_resource",
        "community",
        "commoning_practice",
        "rules_and_responsibility",
        "common_benefit"
      ],
      "properties": {
        "shared_resource": {
          "$ref": "#/$defs/criterion"
        },
        "community": {
          "$ref": "#/$defs/criterion"
        },
        "commoning_practice": {
          "$ref": "#/$defs/criterion"
        },
        "rules_and_responsibility": {
          "$ref": "#/$defs/criterion"
        },
        "common_benefit": {
          "$ref": "#/$defs/criterion"
        }
      }
    },
    "confidence": {
      "type": "number",
      "minimum": 0,
      "maximum": 1
    },
    "limitations": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "type": "string",
        "minLength": 10,
        "maxLength": 500
      }
    },
    "notes": {
      "type": "string",
      "maxLength": 1000
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "decision": {
            "const": "include"
          }
        },
        "required": [
          "decision"
        ]
      },
      "then": {
        "properties": {
          "classification": {
            "enum": [
              "common",
              "commons-infrastructure"
            ]
          }
        }
      }
    }
  ],
  "$defs": {
    "criterion": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "statement",
        "source_ids"
      ],
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "supported",
            "partial",
            "unsupported",
            "unknown"
          ]
        },
        "statement": {
          "type": "string",
          "minLength": 20,
          "maxLength": 1000
        },
        "source_ids": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9-]{2,95}$"
          }
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "status": {
                "enum": [
                  "supported",
                  "partial"
                ]
              }
            },
            "required": [
              "status"
            ]
          },
          "then": {
            "properties": {
              "source_ids": {
                "minItems": 1
              }
            }
          }
        }
      ]
    }
  }
}
