{
  "$id": "https://powercom-maquassihills.planetgis.co.za/MDM/Loss/Update/Schema1",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "ZoneName": { "type": "string", "code": "Name" },
      "MasterMeters": { "type": "array", "items": { "type": "number" }, "code": "MsMt" },
      "SlaveMeters": { "type": "array", "items": { "type": "number" }, "code": "SlMt" },
      "Date": { "type": "string", "format": "date-time", "code": "" },
      "MasterConsumption": { "type": ["number"], "code": "MsCn" },
      "SlaveConsumption": { "type": ["number"], "code": "SlCn" },
      "LossKWh": { "type": ["number","null"], "code": "LsKW" },
      "LossPercent": { "type": ["number","null"], "code": "LsPr" },
      "PercentForAlert": { "type": ["number","null"], "code": "PrFA" },
      "Alert": { "type": ["boolean","null"], "code": "Alrt" }
    },
    "required": ["ZoneName", "MasterMeters", "SlaveMeters"],
    "calculated": {
      "I": { "sql": "Coalesce((SELECT FeatureId FROM f_powercom_energy_loss_zones WHERE ZoneName=:ZoneName), CreateEntity(807000071191751718))" },
      "G": {
        "sql": "GeomCreateHull(Easting, Northing) FROM features WHERE FeatureId IN (
                  SELECT FeatureId FROM f_powercom_meters WHERE MDMID IN (
                    SELECT value FROM json_each(:MasterMeters)
                    UNION SELECT value FROM json_each(:SlaveMeters)
                  )
                )"
      },
      "L": { "expression": "ZoneName" }
    }
  }
}