{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://homeunitscan.com/schemas/HomeUnitScanSchema/1.0.0",
  "title": "HomeUnitScan",
  "description": "MCP-compliant schema for PAI/AI Agent interoperability. Represents a complete home HVAC audit session suitable for ingestion by contractor AI agents and CRM systems (ServiceTitan, FieldEdge, etc.).",
  "type": "object",
  "required": ["audit_metadata", "systems", "financials"],
  "properties": {
    "audit_metadata": {
      "type": "object",
      "description": "Session-level metadata and provenance information.",
      "required": ["version", "verification_hash", "timestamp", "location"],
      "properties": {
        "version": {
          "type": "string",
          "description": "Schema version this payload conforms to.",
          "examples": ["1.0.0"]
        },
        "verification_hash": {
          "type": "string",
          "description": "Deterministic hex digest of canonical session data for tamper detection."
        },
        "timestamp": {
          "type": "string",
          "format": "date-time",
          "description": "ISO-8601 timestamp of when the audit session was generated."
        },
        "location": {
          "type": "object",
          "required": ["zip_code"],
          "properties": {
            "zip_code": { "type": "string", "pattern": "^\\d{5}$" },
            "gas_at_street": {
              "type": ["boolean", "null"],
              "description": "Whether natural gas is available at the street. Derived from fuel type data."
            },
            "grid_region": {
              "type": "string",
              "description": "Electrical grid region for emissions and rate calculations.",
              "examples": ["MISO", "PJM", "WECC", "ERCOT", "SERC", "unknown"]
            }
          }
        }
      }
    },
    "systems": {
      "type": "array",
      "description": "One entry per logical HVAC system in the home.",
      "items": {
        "type": "object",
        "required": ["id", "type", "intent", "components"],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Stable UUID for this system across sessions."
          },
          "type": {
            "type": "string",
            "enum": ["split_system", "boiler", "ductless", "package", "water_heater", "unknown"],
            "description": "Physical system configuration."
          },
          "intent": {
            "type": "string",
            "enum": ["replacement", "supplemental", "conversion"],
            "description": "Homeowner intent for this system."
          },
          "components": {
            "type": "array",
            "description": "Physical units that make up this system.",
            "items": {
              "type": "object",
              "required": ["role", "technical_specs"],
              "properties": {
                "role": {
                  "type": "string",
                  "enum": ["indoor_unit", "outdoor_unit", "coil", "boiler", "water_heater", "other"]
                },
                "manufacturer": { "type": ["string", "null"] },
                "model_number": { "type": ["string", "null"] },
                "serial_number": { "type": ["string", "null"] },
                "year_manufactured": { "type": ["integer", "null"], "minimum": 1970, "maximum": 2100 },
                "ocr_confidence": {
                  "type": ["number", "null"],
                  "minimum": 0,
                  "maximum": 1,
                  "description": "AI extraction confidence score for this component's data tag."
                },
                "technical_specs": {
                  "type": "object",
                  "properties": {
                    "capacity_btu": { "type": ["number", "null"] },
                    "tonnage": { "type": ["number", "null"] },
                    "afue_rating": { "type": ["number", "null"], "minimum": 0, "maximum": 100 },
                    "seer_rating": { "type": ["number", "null"] },
                    "refrigerant_type": { "type": ["string", "null"], "enum": ["R-22", "R-410A", "R-32", "R-454B", null] },
                    "venting_category": { "type": ["string", "null"], "enum": ["I", "II", "III", "IV", null] },
                    "fuel_type": { "type": ["string", "null"], "enum": ["gas", "oil", "electric", "propane", null] },
                    "equipment_type_raw": { "type": ["string", "null"] }
                  }
                }
              }
            }
          },
          "infrastructure_variables": {
            "type": "object",
            "properties": {
              "electrical": {
                "type": "object",
                "properties": {
                  "main_breaker_amps": { "type": ["number", "null"] },
                  "available_slots": { "type": ["number", "null"] },
                  "voltage_verified": { "type": ["boolean", "null"] }
                }
              },
              "ductwork": {
                "type": "object",
                "properties": {
                  "trunk_dimensions": { "type": ["string", "null"] },
                  "estimated_max_cfm": { "type": ["number", "null"] },
                  "static_pressure_risk_score": {
                    "type": ["string", "null"],
                    "enum": ["low", "medium", "high", null]
                  }
                }
              },
              "gas_supply": {
                "type": "object",
                "properties": {
                  "pipe_diameter_inches": { "type": ["string", "null"] },
                  "combustion_air_method": { "type": ["string", "null"] }
                }
              },
              "line_set": {
                "type": "object",
                "properties": {
                  "suction_line_diameter": { "type": ["string", "null"] },
                  "estimated_length_feet": { "type": ["number", "null"] }
                }
              },
              "installation_notes": {
                "type": "object",
                "properties": {
                  "location": { "type": ["string", "null"] },
                  "condenser_mounting": { "type": ["string", "null"] },
                  "accessibility": { "type": ["string", "null"] },
                  "drainage": { "type": ["string", "null"] }
                }
              }
            }
          }
        }
      }
    },
    "financials": {
      "type": "object",
      "properties": {
        "estimated_replacement_cost": { "type": ["number", "null"] },
        "commission_savings": { "type": ["number", "null"] },
        "contingency_buffer": { "type": ["number", "null"] },
        "eligible_rebates": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["source", "amount", "status"],
            "properties": {
              "source": {
                "type": "string",
                "enum": ["federal_25c", "federal_25d", "utility_rebate", "state", "manufacturer"]
              },
              "amount": { "type": "number" },
              "status": { "type": "string", "enum": ["verified", "estimated"] }
            }
          }
        }
      }
    }
  }
}
