{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aicontext.gr/specification/schemas/context.schema.json",
  "title": "AI Context",
  "type": "object",
  "required": ["format", "version", "specification_version", "updated", "status"],
  "additionalProperties": true,
  "properties": {
    "format": {
      "const": "AI Context"
    },
    "version": {
      "type": "string",
      "description": "Publisher content version for this publication"
    },
    "specification_version": {
      "type": "string",
      "description": "AI Context Specification version this document conforms to"
    },
    "updated": {
      "type": "string"
    },
    "status": {
      "type": "string"
    },
    "canonical_url": {
      "type": "string",
      "format": "uri"
    },
    "municipality": {
      "$ref": "#/$defs/organisationBlock"
    },
    "organisation": {
      "$ref": "#/$defs/organisationBlock"
    },
    "contacts": {
      "type": "object",
      "description": "Named contact channels. Object keys are stable contact identifiers.",
      "additionalProperties": true
    },
    "departments": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/department"
      }
    },
    "services": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/service"
      }
    },
    "events": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/event"
      }
    }
  },
  "$defs": {
    "organisationBlock": {
      "type": "object",
      "required": ["name"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$",
          "description": "Stable organisation identifier within this context"
        },
        "name": { "type": "string" },
        "name_en": { "type": "string" },
        "url": { "type": "string", "format": "uri" },
        "scope": { "type": "string" }
      },
      "additionalProperties": true
    },
    "department": {
      "type": "object",
      "required": ["id", "name"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$"
        },
        "name": { "type": "string" },
        "name_en": { "type": "string" },
        "responsibilities": {
          "type": "array",
          "items": { "type": "string" }
        }
      },
      "additionalProperties": true
    },
    "sourceCitation": {
      "type": "object",
      "required": ["id", "url"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "type": {
          "type": "string",
          "enum": [
            "official_page",
            "official_form",
            "official_announcement",
            "official_portal",
            "other"
          ]
        },
        "title": { "type": "string" },
        "last_checked": { "type": "string" }
      },
      "additionalProperties": false
    },
    "service": {
      "type": "object",
      "required": ["id", "name"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$"
        },
        "name": { "type": "string" },
        "name_en": { "type": "string" },
        "description": { "type": "string" },
        "department": { "type": "string" },
        "department_id": {
          "type": "string",
          "description": "Stable reference to departments[].id"
        },
        "source": {
          "$ref": "#/$defs/sourceCitation"
        },
        "source_url": {
          "type": "string",
          "format": "uri",
          "description": "Legacy alias for source.url"
        },
        "source_last_checked": {
          "type": "string",
          "description": "Legacy alias for source.last_checked"
        },
        "last_updated": { "type": "string" },
        "freshness_note": { "type": "string" }
      },
      "additionalProperties": true
    },
    "event": {
      "type": "object",
      "required": ["id", "name"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$"
        },
        "name": { "type": "string" },
        "name_en": { "type": "string" },
        "type": { "type": "string" },
        "status": { "type": "string" },
        "source": {
          "$ref": "#/$defs/sourceCitation"
        },
        "official_source_url": {
          "type": "string",
          "format": "uri",
          "description": "Legacy alias for source.url on events"
        },
        "starts_at": { "type": "string" },
        "ends_at": { "type": "string" },
        "expires_at": { "type": "string" },
        "last_updated": { "type": "string" }
      },
      "additionalProperties": true
    }
  }
}
