{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://uwmd.org/schemas/uw-portfolio-profile.schema.json",
  "title": "UW Portfolio Profile",
  "description": "A `.uwportfolio.json` sidecar (RFC 0015, Protocol §XV): typed entities and provenance-backed relationship edges spanning UW Markdown deals. The portable carrier for the ENTITY layer of the RFC 0018 edge registry. Out-of-band by design: a sidecar is not part of any `.uwx.md` file, claims no `_meta` ownership, and changes no record's canonical bytes. This schema enforces structure only; the registry-aware rules a validator adds (`validatePortfolioProfile`): unique ids across entities and edges (PORT-006), edge endpoints resolving locally (PORT-008), non-empty provenance per edge (PORT-009), a KNOWN edge type used on the member layer refused (PORT-010), and builtin from/to entity-kind constraints (PORT-011). Unknown entity fields, entity types, and edge types are PRESERVED and reportable, never refused — which is why `additionalProperties` stays open throughout. Provenance `source` is a document/source identifier, NOT the RFC 0031 `_meta.source` actor grammar.",
  "type": "object",
  "required": ["portfolio_version", "entities", "edges"],
  "properties": {
    "portfolio_version": {
      "const": "1.0",
      "description": "The sidecar's own semver line, independent of the UW format and protocol versions."
    },
    "portfolio_id": {
      "type": "string",
      "minLength": 1,
      "description": "Recommended stable identifier for the portfolio this sidecar describes."
    },
    "entities": {
      "type": "array",
      "items": { "$ref": "#/$defs/entity" }
    },
    "edges": {
      "type": "array",
      "items": { "$ref": "#/$defs/edge" }
    }
  },
  "$defs": {
    "entity": {
      "type": "object",
      "required": ["id", "type"],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Opaque, case-sensitive, unique within the profile. Consumers MUST NOT derive identity from an id's spelling — a `property:` prefix is producer convention, not grammar."
        },
        "type": {
          "type": "string",
          "minLength": 1,
          "description": "One of the initial registered types (property, deal, borrower, loan, document) or an extension type, which consumers MUST preserve and MAY report as uninterpreted."
        },
        "display_name": { "type": "string" },
        "deal_id": {
          "type": "string",
          "minLength": 1,
          "description": "For property/deal entities: MUST exactly equal the referenced deal's canonical frontmatter `deal_id` when the deal is available — the sidecar's one anchor into the records it describes."
        }
      }
    },
    "edge": {
      "type": "object",
      "required": ["id", "type", "from", "to", "provenance"],
      "description": "Exactly the RFC 0018 `UWEntityEdge` shape plus a profile-unique `id`. Edge types resolve against the canonical protocol registry (`BUILTIN_EDGE_TYPES`); this schema deliberately does not enumerate them — the registry is the single home (RFC 0018 §5).",
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "type": { "type": "string", "minLength": 1 },
        "from": { "type": "string", "minLength": 1 },
        "to": { "type": "string", "minLength": 1 },
        "provenance": {
          "type": "array",
          "minItems": 1,
          "items": { "$ref": "#/$defs/provenance" }
        }
      }
    },
    "provenance": {
      "type": "object",
      "required": ["source"],
      "properties": {
        "source": {
          "type": "string",
          "minLength": 1,
          "description": "Stable document/source identifier — which artifact says so. NOT the `_meta.source` actor grammar (RFC 0031); the two vocabularies stay apart by construction."
        },
        "locator": { "type": "string", "description": "Where in the source (page, section, cell). Free text in 1.0, the lease-abstract posture." },
        "note": { "type": "string" },
        "retrieved_at": { "type": "string", "description": "ISO-8601 timestamp of retrieval, when meaningful." }
      }
    }
  }
}
