{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "school.schema.json",
  "title": "MCPS per-school profile (data/schools/<code>.json)",
  "description": "One consolidated record per school. Identity (crosswalk) + MSDE academics/accountability/climate + neighborhood income/housing + MCPS reports. Rollup/empty codes carry only identity and are dropped by the consumer (names absent).",
  "type": "object",
  "required": ["school_code", "names", "type"],
  "additionalProperties": false,
  "properties": {
    "school_code": { "type": "string", "description": "3-digit MCPS code (join key)" },
    "names": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "official": { "type": ["string", "null"] },
        "short": { "type": ["string", "null"] }
      }
    },
    "type": { "type": "string", "description": "ES / MS / HS (\"\" for rollup codes)" },
    "cluster": { "type": "string" },
    "address": { "type": "string" },
    "zip": { "type": "string" },
    "lat": { "type": ["number", "null"] },
    "lon": { "type": ["number", "null"] },
    "in": {
      "type": "object",
      "description": "crosswalk coverage flags (in_gis / in_income / in_reports / in_bus)",
      "additionalProperties": { "type": "boolean" }
    },
    "accountability": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["year"],
        "additionalProperties": false,
        "properties": {
          "year": { "type": "string" },
          "rating": { "type": ["number", "null"] },
          "points_pct": { "type": ["number", "null"] },
          "percentile": { "type": ["number", "null"] }
        }
      }
    },
    "academics": { "$ref": "#/$defs/academics" },
    "climate": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "attendance_rate": { "$ref": "#/$defs/pointArray" },
        "chronic_absenteeism": { "$ref": "#/$defs/pointArray" }
      }
    },
    "students": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "enrollment_by_race_latest": { "$ref": "#/$defs/numMap" },
        "latest_year": { "type": ["string", "null"] },
        "enrollment_trend": { "$ref": "#/$defs/pointArray" }
      }
    },
    "per_pupil": { "$ref": "#/$defs/pointArray" },
    "educator": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "poverty_band": { "type": ["string", "null"] },
        "inexperienced_teacher_pct": { "$ref": "#/$defs/pointArray" },
        "out_of_field_pct": { "$ref": "#/$defs/pointArray" },
        "emergency_cred_pct": { "$ref": "#/$defs/pointArray" }
      }
    },
    "neighborhood": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "acs_year": { "type": ["integer", "string", "null"] },
        "boundary_level": { "type": "string" },
        "income": {
          "type": ["object", "null"],
          "additionalProperties": { "type": ["number", "null", "boolean"] }
        },
        "demographics": {
          "type": ["object", "null"],
          "additionalProperties": { "type": ["number", "null"] }
        },
        "family_with_children_income": {
          "type": ["object", "null"],
          "additionalProperties": { "type": ["number", "null"] }
        },
        "property": { "type": ["object", "null"] }
      }
    },
    "paired": {
      "type": "object",
      "description": "Grade-band paired school: shares one attendance area (and its neighborhood data) with a host school, split by grade. Present only on the upper-grade partner.",
      "additionalProperties": false,
      "properties": {
        "host_code": { "type": "string" },
        "host_name": { "type": "string" },
        "partner_grades": { "type": ["string", "null"] },
        "host_grades": { "type": ["string", "null"] }
      }
    },
    "school_reports": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "programs": { "type": "array", "items": { "type": "string" } },
        "suspension_rate": { "$ref": "#/$defs/pointArray" },
        "sat": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["year", "metric", "value"],
            "additionalProperties": true,
            "properties": {
              "year": { "type": "string" },
              "metric": { "type": "string" },
              "value": { "type": "number" }
            }
          }
        }
      }
    },
    "sources": {
      "type": "object",
      "additionalProperties": { "type": "boolean" }
    }
  },
  "$defs": {
    "point": {
      "type": "object",
      "required": ["year", "value"],
      "additionalProperties": false,
      "properties": {
        "year": { "type": "string" },
        "value": { "type": ["number", "null"] },
        "suppressed": {
          "type": ["string", "boolean"],
          "description": "privacy suppression: MSDE range text (\">= 95.0\") or a boolean flag"
        }
      }
    },
    "pointArray": { "type": "array", "items": { "$ref": "#/$defs/point" } },
    "numMap": {
      "type": "object",
      "description": "dynamic {label: value} map (subgroups, races); null = privacy-suppressed",
      "additionalProperties": { "type": ["number", "null"] }
    },
    "subject": {
      "type": "object",
      "additionalProperties": false,
      "required": ["pct_proficient"],
      "properties": {
        "pct_proficient": { "$ref": "#/$defs/pointArray" },
        "latest_year": { "type": "string" },
        "by_group_latest": { "$ref": "#/$defs/numMap" },
        "by_group_school": { "$ref": "#/$defs/numMap" },
        "by_group_school_trend": {
          "type": "object",
          "additionalProperties": { "$ref": "#/$defs/pointArray" }
        }
      }
    },
    "academics": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "ela": { "$ref": "#/$defs/subject" },
        "math": { "$ref": "#/$defs/subject" },
        "science": { "$ref": "#/$defs/subject" },
        "grad_rate": { "$ref": "#/$defs/pointArray" }
      }
    }
  }
}
