{
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "$id": "https://dashremix.com/spec/vehicle/1.0.0/vehicle@1.schema.json",
 "title": "vehicle@1 v1.0.0",
 "description": "One property per table (an array of rows). Generated from schema.sql by spec/build.py. Extension tables (x_<owner>_*) belong to forks and board-derived tables (d_*) to the board that rebuilds them; both are allowed as additional properties.",
 "type": "object",
 "properties": {
  "meta": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "key": {
      "type": "string"
     },
     "value": {
      "type": [
       "string",
       "null"
      ]
     }
    },
    "required": [
     "key"
    ],
    "additionalProperties": false
   }
  },
  "vehicles": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "vehicle_id": {
      "type": "string"
     },
     "label": {
      "type": "string"
     },
     "powertrain": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "combustion",
       "hybrid",
       "plug_in_hybrid",
       "battery_electric",
       "fuel_cell",
       "other",
       null
      ]
     },
     "active_from": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "active_to": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "source": {
      "type": "string"
     },
     "source_ref": {
      "type": "string"
     },
     "imported_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "confidence": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "source",
       "rule",
       "default",
       "detected",
       "manual",
       null
      ]
     }
    },
    "required": [
     "vehicle_id",
     "label",
     "source",
     "source_ref",
     "imported_at"
    ],
    "additionalProperties": false
   }
  },
  "odometer_readings": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "reading_id": {
      "type": "string"
     },
     "vehicle_id": {
      "type": "string"
     },
     "day": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "odometer_m": {
      "type": "integer"
     },
     "source": {
      "type": "string"
     },
     "source_ref": {
      "type": "string"
     },
     "imported_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "confidence": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "source",
       "rule",
       "default",
       "detected",
       "manual",
       null
      ]
     }
    },
    "required": [
     "reading_id",
     "vehicle_id",
     "day",
     "odometer_m",
     "source",
     "source_ref",
     "imported_at"
    ],
    "additionalProperties": false
   }
  },
  "energy_purchases": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "purchase_id": {
      "type": "string"
     },
     "vehicle_id": {
      "type": "string"
     },
     "day": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "energy_kind": {
      "type": "string",
      "enum": [
       "gasoline",
       "diesel",
       "electricity",
       "other_liquid",
       "other",
       "unknown"
      ]
     },
     "volume_l": {
      "type": [
       "number",
       "null"
      ]
     },
     "energy_wh": {
      "type": [
       "number",
       "null"
      ]
     },
     "fill_complete": {
      "type": [
       "integer",
       "null"
      ]
     },
     "reading_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "cost_amount": {
      "type": [
       "number",
       "null"
      ]
     },
     "currency": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^[A-Z]{3}$"
     },
     "cost_base": {
      "type": [
       "number",
       "null"
      ]
     },
     "source": {
      "type": "string"
     },
     "source_ref": {
      "type": "string"
     },
     "imported_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "confidence": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "source",
       "rule",
       "default",
       "detected",
       "manual",
       null
      ]
     }
    },
    "required": [
     "purchase_id",
     "vehicle_id",
     "day",
     "energy_kind",
     "source",
     "source_ref",
     "imported_at"
    ],
    "additionalProperties": false
   }
  },
  "service_records": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "service_id": {
      "type": "string"
     },
     "vehicle_id": {
      "type": "string"
     },
     "day": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "reading_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "description": {
      "type": [
       "string",
       "null"
      ]
     },
     "cost_amount": {
      "type": [
       "number",
       "null"
      ]
     },
     "currency": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^[A-Z]{3}$"
     },
     "cost_base": {
      "type": [
       "number",
       "null"
      ]
     },
     "source": {
      "type": "string"
     },
     "source_ref": {
      "type": "string"
     },
     "imported_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "confidence": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "source",
       "rule",
       "default",
       "detected",
       "manual",
       null
      ]
     }
    },
    "required": [
     "service_id",
     "vehicle_id",
     "day",
     "source",
     "source_ref",
     "imported_at"
    ],
    "additionalProperties": false
   }
  },
  "service_tasks": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "task_id": {
      "type": "string"
     },
     "vehicle_id": {
      "type": "string"
     },
     "label": {
      "type": "string"
     },
     "service_kind": {
      "type": "string",
      "enum": [
       "oil",
       "tyres",
       "brakes",
       "battery",
       "inspection",
       "fluids",
       "filters",
       "repair",
       "other"
      ]
     },
     "interval_days": {
      "type": [
       "integer",
       "null"
      ]
     },
     "interval_m": {
      "type": [
       "integer",
       "null"
      ]
     },
     "due_on": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "due_odometer_m": {
      "type": [
       "integer",
       "null"
      ]
     },
     "source": {
      "type": "string"
     },
     "source_ref": {
      "type": "string"
     },
     "imported_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "confidence": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "source",
       "rule",
       "default",
       "detected",
       "manual",
       null
      ]
     }
    },
    "required": [
     "task_id",
     "vehicle_id",
     "label",
     "service_kind",
     "source",
     "source_ref",
     "imported_at"
    ],
    "additionalProperties": false
   }
  },
  "service_items": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "service_id": {
      "type": "string"
     },
     "task_id": {
      "type": "string"
     },
     "source": {
      "type": "string"
     },
     "source_ref": {
      "type": "string"
     },
     "imported_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "confidence": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "source",
       "rule",
       "default",
       "detected",
       "manual",
       null
      ]
     }
    },
    "required": [
     "service_id",
     "task_id",
     "source",
     "source_ref",
     "imported_at"
    ],
    "additionalProperties": false
   }
  },
  "data_issues": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "issue_id": {
      "type": "string"
     },
     "severity": {
      "type": "string",
      "enum": [
       "info",
       "warn",
       "error"
      ]
     },
     "kind": {
      "type": "string"
     },
     "title": {
      "type": "string"
     },
     "detail": {
      "type": "string"
     },
     "source": {
      "type": "string"
     },
     "source_ref": {
      "type": "string"
     },
     "imported_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "handling": {
      "type": "string"
     }
    },
    "required": [
     "issue_id",
     "severity",
     "kind",
     "title",
     "detail",
     "source",
     "source_ref",
     "imported_at",
     "handling"
    ],
    "additionalProperties": false
   }
  },
  "overrides": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "override_id": {
      "type": "string"
     },
     "target": {
      "type": "string"
     },
     "field": {
      "type": [
       "string",
       "null"
      ]
     },
     "old_value": {
      "type": [
       "string",
       "null"
      ]
     },
     "new_value": {
      "type": [
       "string",
       "null"
      ]
     },
     "reason": {
      "type": "string"
     },
     "evidence": {
      "type": [
       "string",
       "null"
      ]
     },
     "author": {
      "type": [
       "string",
       "null"
      ]
     },
     "created_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     }
    },
    "required": [
     "override_id",
     "target",
     "reason"
    ],
    "additionalProperties": false
   }
  },
  "annotations": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "annotation_id": {
      "type": "string"
     },
     "target": {
      "type": "string"
     },
     "kind": {
      "type": "string"
     },
     "body": {
      "type": "string"
     },
     "author": {
      "type": [
       "string",
       "null"
      ]
     },
     "source_ref": {
      "type": [
       "string",
       "null"
      ]
     },
     "created_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "data_hash": {
      "type": [
       "string",
       "null"
      ]
     },
     "status": {
      "type": [
       "string",
       "null"
      ]
     }
    },
    "required": [
     "annotation_id",
     "target",
     "kind",
     "body"
    ],
    "additionalProperties": false
   }
  },
  "metric_registry": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "metric_id": {
      "type": "string"
     },
     "version": {
      "type": [
       "integer",
       "null"
      ]
     },
     "unit": {
      "type": [
       "string",
       "null"
      ]
     },
     "params": {
      "type": [
       "string",
       "null"
      ]
     },
     "description": {
      "type": [
       "string",
       "null"
      ]
     },
     "sql": {
      "type": [
       "string",
       "null"
      ]
     },
     "test": {
      "type": [
       "string",
       "null"
      ]
     }
    },
    "required": [
     "metric_id"
    ],
    "additionalProperties": false
   }
  }
 },
 "required": [
  "meta",
  "vehicles",
  "odometer_readings",
  "energy_purchases",
  "service_records",
  "service_tasks",
  "service_items"
 ],
 "patternProperties": {
  "^x_[a-z0-9_]+$": {
   "type": "array"
  },
  "^d_[a-z0-9_]+$": {
   "type": "array"
  }
 },
 "additionalProperties": false
}
