{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$comment": "Copyright \u00a9 2026 Stephen Makonin. Draft schema.",
  "$id": "https://carbonkit.org/schemas/0.1/activity.schema.json",
  "title": "CarbonKit activity record - proposal 0.1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "spec_version",
    "id",
    "subject_ref",
    "provider_ref",
    "created_at",
    "boundary",
    "consent_ref",
    "supersedes",
    "record_type",
    "source_ref",
    "start",
    "end",
    "category",
    "quantity",
    "quality",
    "coverage"
  ],
  "properties": {
    "spec_version": {
      "const": "0.1"
    },
    "id": {
      "type": "string",
      "minLength": 1
    },
    "subject_ref": {
      "type": "string",
      "minLength": 1
    },
    "provider_ref": {
      "type": "string",
      "minLength": 1
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "boundary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "description",
        "geography"
      ],
      "properties": {
        "description": {
          "type": "string",
          "minLength": 1
        },
        "geography": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "consent_ref": {
      "type": "string",
      "minLength": 1
    },
    "supersedes": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 1
    },
    "record_type": {
      "const": "activity"
    },
    "source_ref": {
      "type": "string",
      "minLength": 1
    },
    "start": {
      "type": "string",
      "format": "date-time"
    },
    "end": {
      "type": "string",
      "format": "date-time"
    },
    "category": {
      "const": "electricity"
    },
    "quantity": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "value",
        "unit"
      ],
      "properties": {
        "value": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0
        },
        "unit": {
          "const": "kWh"
        }
      }
    },
    "quality": {
      "enum": [
        "observed",
        "estimated",
        "missing"
      ]
    },
    "coverage": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "reason"
      ],
      "properties": {
        "status": {
          "enum": [
            "complete",
            "partial",
            "unknown"
          ]
        },
        "reason": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "quality": {
            "const": "missing"
          }
        }
      },
      "then": {
        "properties": {
          "quantity": {
            "properties": {
              "value": {
                "type": "null"
              }
            }
          },
          "coverage": {
            "properties": {
              "reason": {
                "type": "string",
                "minLength": 1
              }
            }
          }
        }
      },
      "else": {
        "properties": {
          "quantity": {
            "properties": {
              "value": {
                "type": "number"
              }
            }
          }
        }
      }
    }
  ]
}
