{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://trp.ecoclaim.ca/schemas/v3/waste-event.schema.json",
  "title": "TRP WasteEvent",
  "description": "A debris or waste movement with measurement, destination and evidence. Draft 3.0.0-draft.",
  "allOf": [{ "$ref": "common.schema.json#/$defs/envelope" }],
  "type": "object",
  "required": ["claim_id", "job_id", "material_stream", "quantity", "measurement_method", "event_time", "reported_by", "verification_status"],
  "properties": {
    "type": { "const": "trp.waste_event" },
    "claim_id": { "$ref": "common.schema.json#/$defs/identifier" },
    "job_id": { "$ref": "common.schema.json#/$defs/identifier" },
    "material_stream": {
      "enum": ["wood", "drywall", "concrete", "asphalt_shingle", "metal_ferrous", "metal_nonferrous", "carpet", "vinyl_flooring", "insulation", "glass", "plastic", "mixed_cd", "electronics", "appliance", "contents_mixed", "hazardous_regulated", "other"]
    },
    "quantity": { "$ref": "common.schema.json#/$defs/quantity" },
    "quantity_reason_code": { "type": "string" },
    "weights": {
      "type": "object",
      "properties": {
        "gross": { "$ref": "common.schema.json#/$defs/quantity" },
        "tare": { "$ref": "common.schema.json#/$defs/quantity" },
        "net": { "$ref": "common.schema.json#/$defs/quantity" }
      }
    },
    "measurement_method": {
      "enum": ["certified_scale", "facility_receipt", "onsite_scale", "volume_density", "estimate_derived"]
    },
    "event_time": { "$ref": "common.schema.json#/$defs/timestamp" },
    "reported_by": { "$ref": "common.schema.json#/$defs/identifier" },
    "carrier": { "$ref": "common.schema.json#/$defs/identifier" },
    "destination_facility": { "$ref": "common.schema.json#/$defs/identifier" },
    "ticket_id": { "$ref": "common.schema.json#/$defs/identifier" },
    "processing_outcome": {
      "enum": ["unknown", "landfilled", "recycled", "reused", "energy_recovery", "treated", "other"]
    },
    "outcome_evidence_status": { "enum": ["none", "reported", "facility_confirmed"] },
    "allocation_fraction": { "type": "number", "exclusiveMinimum": 0, "maximum": 1 },
    "verification_status": { "$ref": "common.schema.json#/$defs/verificationStatus" }
  },
  "if": {
    "required": ["quantity"],
    "properties": {
      "quantity": {
        "type": "object",
        "required": ["value"],
        "properties": { "value": { "type": "number", "maximum": 0 } }
      }
    }
  },
  "then": {
    "required": ["quantity_reason_code"],
    "properties": { "quantity_reason_code": { "type": "string", "minLength": 1 } }
  }
}
