{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://nodedc.local/ontology/seo/project-ontology.schema.json",
  "title": "SEO Project Ontology Instance",
  "type": "object",
  "required": [
    "schemaVersion",
    "projectId",
    "siteId",
    "coreOntologyVersion",
    "seoDomainPackageVersion",
    "source",
    "scope",
    "brand",
    "pages",
    "sections",
    "intentClusters",
    "tone",
    "constraints",
    "evidence",
    "approvals"
  ],
  "additionalProperties": false,
  "properties": {
    "schemaVersion": { "const": "seo-project-ontology.v1" },
    "projectId": { "type": "string", "minLength": 1 },
    "siteId": { "type": "string", "minLength": 1 },
    "coreOntologyVersion": { "type": "string", "minLength": 1 },
    "seoDomainPackageVersion": { "type": "string", "minLength": 1 },
    "source": {
      "type": "object",
      "required": ["sourceType", "scanVersionId"],
      "additionalProperties": false,
      "properties": {
        "sourceType": {
          "type": "string",
          "enum": ["local_folder", "browser_folder", "uploaded_package", "repository", "live_crawl"]
        },
        "scanVersionId": { "type": "string", "minLength": 1 },
        "rootUrl": { "type": ["string", "null"] },
        "sourcePath": { "type": ["string", "null"] }
      }
    },
    "scope": {
      "type": "object",
      "required": ["scopeContractId", "scopeItemIds"],
      "additionalProperties": false,
      "properties": {
        "scopeContractId": { "type": "string", "minLength": 1 },
        "scopeItemIds": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        }
      }
    },
    "brand": {
      "type": "object",
      "required": ["name", "aliases", "description"],
      "additionalProperties": false,
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "aliases": { "type": "array", "items": { "type": "string" } },
        "description": { "type": "string" }
      }
    },
    "offers": {
      "type": "array",
      "items": { "$ref": "#/$defs/namedEvidenceItem" }
    },
    "audiences": {
      "type": "array",
      "items": { "$ref": "#/$defs/namedEvidenceItem" }
    },
    "pages": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "url", "title", "evidenceIds"],
        "additionalProperties": false,
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "url": { "type": "string" },
          "title": { "type": "string" },
          "evidenceIds": { "$ref": "#/$defs/evidenceIds" }
        }
      }
    },
    "sections": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "pageId", "title", "meaning", "evidenceIds"],
        "additionalProperties": false,
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "pageId": { "type": "string", "minLength": 1 },
          "title": { "type": "string" },
          "meaning": { "type": "string" },
          "evidenceIds": { "$ref": "#/$defs/evidenceIds" }
        }
      }
    },
    "intentClusters": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "title", "priority", "targetIntent", "seedQueries", "evidenceIds"],
        "additionalProperties": false,
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "title": { "type": "string", "minLength": 1 },
          "priority": { "type": "string", "enum": ["high", "medium", "low"] },
          "targetIntent": { "type": "string" },
          "seedQueries": {
            "type": "array",
            "items": { "type": "string", "minLength": 1 }
          },
          "evidenceIds": { "$ref": "#/$defs/evidenceIds" }
        }
      }
    },
    "tone": {
      "type": "object",
      "required": ["language", "signals", "forbiddenShifts"],
      "additionalProperties": false,
      "properties": {
        "language": { "type": "string" },
        "signals": { "type": "array", "items": { "type": "string" } },
        "forbiddenShifts": { "type": "array", "items": { "type": "string" } }
      }
    },
    "constraints": {
      "type": "object",
      "required": ["forbiddenTopics", "forbiddenClaims", "mustKeep"],
      "additionalProperties": false,
      "properties": {
        "forbiddenTopics": { "type": "array", "items": { "type": "string" } },
        "forbiddenClaims": { "type": "array", "items": { "type": "string" } },
        "mustKeep": { "type": "array", "items": { "type": "string" } }
      }
    },
    "evidence": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "sourceType", "ref", "summary"],
        "additionalProperties": false,
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "sourceType": { "type": "string" },
          "ref": { "type": "string" },
          "summary": { "type": "string" }
        }
      }
    },
    "approvals": {
      "type": "object",
      "required": ["status", "approvedBy", "approvedAt"],
      "additionalProperties": false,
      "properties": {
        "status": { "type": "string", "enum": ["draft", "approved", "rejected", "needs_review"] },
        "approvedBy": { "type": ["string", "null"] },
        "approvedAt": { "type": ["string", "null"] }
      }
    },
    "ontologyDeltaProposals": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "target", "summary", "status"],
        "additionalProperties": false,
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "target": { "type": "string", "enum": ["core", "seo_domain", "project_only"] },
          "summary": { "type": "string" },
          "status": { "type": "string", "enum": ["proposed", "accepted", "rejected", "deferred"] }
        }
      }
    }
  },
  "$defs": {
    "evidenceIds": {
      "type": "array",
      "items": { "type": "string", "minLength": 1 },
      "uniqueItems": true
    },
    "namedEvidenceItem": {
      "type": "object",
      "required": ["id", "name", "summary", "evidenceIds"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "name": { "type": "string", "minLength": 1 },
        "summary": { "type": "string" },
        "evidenceIds": { "$ref": "#/$defs/evidenceIds" }
      }
    }
  }
}
