{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "f250-federal-group-relationships-v1",
  "title": "Freedom 250 Federal Group typed relationships and membership",
  "type": "object",
  "required": [
    "schema_version",
    "title",
    "status",
    "evidence_cutoff",
    "claim_boundary",
    "provenance",
    "endpoints",
    "relationships",
    "membership_profiles"
  ],
  "additionalProperties": false,
  "properties": {
    "schema_version": {"const": "f250.federal-group-relationships/v1"},
    "title": {"type": "string", "minLength": 1},
    "status": {"enum": ["promotion_staging_review_only", "chronicle_owned_reviewed"]},
    "evidence_cutoff": {"type": "string", "minLength": 1},
    "claim_boundary": {"type": "string", "minLength": 1},
    "provenance": {"$ref": "#/$defs/provenance"},
    "endpoints": {"type": "array", "items": {"$ref": "#/$defs/endpoint"}},
    "relationships": {"type": "array", "items": {"$ref": "#/$defs/relationship"}},
    "membership_profiles": {"type": "array", "items": {"$ref": "#/$defs/membership"}}
  },
  "$defs": {
    "slug": {"type": "string", "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"},
    "httpsUrl": {"type": "string", "pattern": "^https://"},
    "clock": {
      "type": ["object", "null"],
      "required": ["value", "precision"],
      "additionalProperties": false,
      "properties": {
        "value": {"type": "string", "minLength": 1},
        "precision": {"enum": ["day", "month", "year", "unknown"]}
      }
    },
    "binding": {
      "type": "object",
      "required": ["mode"],
      "additionalProperties": false,
      "properties": {
        "mode": {"enum": ["tree_path", "tree_explicit_id", "overlay_only", "external_only", "role_only", "instrument_only", "held"]},
        "tree_path": {"type": "string", "minLength": 1},
        "tree_explicit_id": {"type": "string", "minLength": 1},
        "navigation_anchor_ids": {"type": "array", "uniqueItems": true, "items": {"$ref": "#/$defs/slug"}}
      },
      "allOf": [
        {"if": {"properties": {"mode": {"const": "tree_path"}}}, "then": {"required": ["tree_path"]}},
        {"if": {"properties": {"mode": {"const": "tree_explicit_id"}}}, "then": {"required": ["tree_explicit_id"]}}
      ]
    },
    "endpoint": {
      "type": "object",
      "required": ["endpoint_id", "display_name", "endpoint_kind", "lifecycle_state", "aliases", "binding", "claim_limit"],
      "additionalProperties": false,
      "properties": {
        "endpoint_id": {"$ref": "#/$defs/slug"},
        "display_name": {"type": "string", "minLength": 1},
        "endpoint_kind": {"enum": ["federal_entity", "federal_component", "federal_collective_body", "official_role", "legal_instrument", "historical_body", "ffrdc", "private_administrator"]},
        "lifecycle_state": {"$ref": "#/$defs/lifecycle"},
        "aliases": {"type": "array", "uniqueItems": true, "items": {"$ref": "#/$defs/slug"}},
        "binding": {"$ref": "#/$defs/binding"},
        "claim_limit": {"type": "string", "minLength": 1}
      }
    },
    "lifecycle": {
      "enum": ["verified_current", "source_reported_unverified", "termination_directed", "terminated", "superseded", "reestablished", "held"]
    },
    "relationship": {
      "type": "object",
      "required": ["relationship_id", "from_id", "type", "to_id", "authority_uri", "lifecycle_state", "effective_from", "effective_to", "evidence_cutoff", "evidence_state", "projection_state", "sources", "origin_records", "claim_limit"],
      "additionalProperties": false,
      "properties": {
        "relationship_id": {"$ref": "#/$defs/slug"},
        "from_id": {"$ref": "#/$defs/slug"},
        "type": {"enum": ["established_by", "jointly_established_by", "established_within", "chartered_by", "sponsored_by", "administered_by", "operated_by", "contracted_by", "administratively_supports", "technically_supports", "provides_secretariat", "publishes_for", "hosts", "funds", "sets_policy_for", "approves_major_awards_of", "appointed_by", "chairs", "advises", "participates_in", "member_of", "provides_analysis_to", "reports_to", "commissioned_by", "constitutes_with", "governs_with", "incorporates_mission_of", "succeeds_without_continuity"]},
        "to_id": {"$ref": "#/$defs/slug"},
        "authority_uri": {"$ref": "#/$defs/httpsUrl"},
        "authority_citation": {"type": "string", "minLength": 1},
        "lifecycle_state": {"$ref": "#/$defs/lifecycle"},
        "effective_from": {"$ref": "#/$defs/clock"},
        "effective_to": {"$ref": "#/$defs/clock"},
        "evidence_cutoff": {"type": "string", "minLength": 1},
        "evidence_state": {"enum": ["official_verified", "official_partial", "statutory_design_only", "held"]},
        "projection_state": {"enum": ["active", "registry_only", "held"]},
        "sources": {"type": "array", "minItems": 1, "uniqueItems": true, "items": {"$ref": "#/$defs/httpsUrl"}},
        "origin_records": {"type": "array", "minItems": 1, "uniqueItems": true, "items": {"type": "string", "minLength": 1}},
        "claim_limit": {"type": "string", "minLength": 1}
      }
    },
    "appointmentAuthority": {
      "type": "object",
      "required": ["label", "endpoint_id", "relationship_state"],
      "additionalProperties": false,
      "properties": {
        "label": {"type": "string", "minLength": 1},
        "endpoint_id": {"anyOf": [{"$ref": "#/$defs/slug"}, {"type": "null"}]},
        "relationship_state": {"const": "profile_only"}
      }
    },
    "membership": {
      "type": "object",
      "required": ["body_id", "seat_design", "appointment_authorities", "chair", "composition", "term_design", "current_roster_state", "roster_as_of", "membership_evidence_state", "sources", "claim_limit"],
      "additionalProperties": false,
      "properties": {
        "body_id": {"$ref": "#/$defs/slug"},
        "seat_design": {"type": "string", "minLength": 1},
        "appointment_authorities": {"type": "array", "items": {"$ref": "#/$defs/appointmentAuthority"}},
        "chair": {"type": "string", "minLength": 1},
        "composition": {"type": "string", "minLength": 1},
        "term_design": {"type": "string", "minLength": 1},
        "current_roster_state": {"enum": ["current_roster_verified", "seat_design_verified_names_incomplete", "chartered_reconstituting", "vacancies_reported", "roster_not_recovered", "historical_or_terminated"]},
        "roster_as_of": {"type": ["string", "null"]},
        "membership_evidence_state": {"enum": ["official_verified", "official_partial", "statutory_design_only", "held"]},
        "sources": {"type": "array", "minItems": 1, "uniqueItems": true, "items": {"$ref": "#/$defs/httpsUrl"}},
        "claim_limit": {"type": "string", "minLength": 1}
      }
    },
    "provenance": {
      "type": "object",
      "required": ["imports", "id_aliases", "normalization_receipt"],
      "additionalProperties": false,
      "properties": {
        "imports": {
          "type": "array",
          "minItems": 3,
          "items": {
            "type": "object",
            "required": ["import_id", "source_path", "source_sha256", "record_count", "evidence_cutoff"],
            "additionalProperties": false,
            "properties": {
              "import_id": {"$ref": "#/$defs/slug"},
              "source_path": {"type": "string", "minLength": 1},
              "source_sha256": {"type": "string", "pattern": "^[a-f0-9]{64}$"},
              "record_count": {"type": "integer", "minimum": 0},
              "evidence_cutoff": {"type": "string", "minLength": 1}
            }
          }
        },
        "id_aliases": {"type": "object", "additionalProperties": {"$ref": "#/$defs/slug"}},
        "normalization_receipt": {
          "type": "object",
          "required": ["source_edge_records", "staging_supplemental_relationships", "ffrdc_sponsor_links", "ffrdc_administrator_links", "cross_ledger_duplicates_merged", "unique_relationships", "membership_profiles"],
          "additionalProperties": false,
          "properties": {
            "source_edge_records": {"type": "integer", "minimum": 0},
            "staging_supplemental_relationships": {"type": "integer", "minimum": 0},
            "ffrdc_sponsor_links": {"type": "integer", "minimum": 0},
            "ffrdc_administrator_links": {"type": "integer", "minimum": 0},
            "cross_ledger_duplicates_merged": {"type": "integer", "minimum": 0},
            "unique_relationships": {"type": "integer", "minimum": 0},
            "membership_profiles": {"type": "integer", "minimum": 0}
          }
        }
      }
    }
  }
}
