{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openmobiledocumentagent.org/schemas/v0.1/identity.schema.json",
  "title": "OMDA document identity: segment, entity, relationship, no_match (§4)",
  "$defs": {
    "segment": {
      "type": "object",
      "required": ["id", "super_id", "pages", "status"],
      "additionalProperties": false,
      "properties": {
        "id": { "$ref": "common.schema.json#/$defs/segmentId" },
        "super_id": { "$ref": "common.schema.json#/$defs/superId" },
        "pages": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": ["page"],
            "properties": {
              "page": { "type": "integer", "minimum": 1 },
              "region": { "$ref": "common.schema.json#/$defs/region" }
            }
          }
        },
        "doc_type": { "type": "string" },
        "profile": { "type": "string", "pattern": "^[a-z0-9.-]+@[0-9]+$" },
        "method": { "type": "string" },
        "status": { "enum": ["proposed", "confirmed", "rejected"] }
      }
    },
    "entity": {
      "type": "object",
      "required": ["id", "segments", "doc_type", "status"],
      "additionalProperties": false,
      "properties": {
        "id": { "$ref": "common.schema.json#/$defs/entityId" },
        "segments": { "type": "array", "minItems": 1, "items": { "$ref": "common.schema.json#/$defs/segmentId" } },
        "doc_type": { "type": "string" },
        "status": { "enum": ["active", "expired", "superseded", "archived"] },
        "subject": { "type": ["string", "null"], "description": "Optional opaque local label (informative, OD-012)." }
      }
    },
    "relationship": {
      "type": "object",
      "required": ["id", "type", "from", "to", "status", "evidence"],
      "additionalProperties": false,
      "properties": {
        "id": { "$ref": "common.schema.json#/$defs/relationshipId" },
        "type": { "enum": ["supersedes", "amends", "attached_to", "related", "duplicate_of"] },
        "from": { "$ref": "common.schema.json#/$defs/entityId" },
        "to": { "$ref": "common.schema.json#/$defs/entityId" },
        "status": { "enum": ["proposed", "verified", "confirmed", "rejected"] },
        "evidence": { "type": "array", "minItems": 1, "items": { "$ref": "common.schema.json#/$defs/assertionId" } },
        "decided_at": { "$ref": "common.schema.json#/$defs/timestamp" }
      }
    },
    "no_match": {
      "type": "object",
      "required": ["kind", "entity", "candidates_checked", "at"],
      "additionalProperties": false,
      "properties": {
        "kind": { "const": "no_match" },
        "entity": { "$ref": "common.schema.json#/$defs/entityId" },
        "candidates_checked": { "type": "array", "items": { "$ref": "common.schema.json#/$defs/entityId" } },
        "at": { "$ref": "common.schema.json#/$defs/timestamp" }
      }
    }
  }
}
