{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Vehicle Stat Log",
  "type": "object",
  "properties": {
    "connectionId": {
      "type": "string",
      "description": "The ID of the connection that this record belongs to."
    },
    "id": {
      "title": "VehicleStatLogId",
      "type": "string",
      "format": "ulid"
    },
    "sourceId": {
      "title": "SourceId",
      "type": "string",
      "description": "The ID used to represent the entity in the source system."
    },
    "provider": {
      "type": "string",
      "description": "Every provider has a unique code to identify it across Terminal's system. You can find each provider's code under [provider details](/providers)."
    },
    "type": {
      "type": "string"
    },
    "timestamp": {
      "title": "ISODateTime",
      "type": "string",
      "format": "date-time",
      "description": "[ISO 8601](https://www.w3.org/TR/NOTE-datetime) date"
    },
    "vehicle": {
      "description": "The vehicle this event is about.",
      "title": "VehicleId",
      "type": "string",
      "format": "ulid",
      "pattern": "^vcl_[0-9A-HJKMNP-TV-Z]{26}$"
    },
    "metadata": {
      "title": "TimeSeriesMetadata",
      "type": "object",
      "description": "Internal metadata about the time series.",
      "required": ["modifiedAt"],
      "properties": {
        "modifiedAt": {
          "title": "ModifiedAt",
          "type": "string",
          "format": "date-time",
          "description": "The date and time the record was last updated in Terminal. Note: this is not the date and time the record was updated in the provider's system."
        }
      }
    },
    "raw": {
      "title": "RawDataList",
      "type": "array",
      "items": {
        "title": "RawData",
        "type": "object",
        "properties": {
          "provider": {
            "type": "string"
          },
          "schema": {
            "type": "string"
          },
          "extractedAt": {
            "type": "string"
          },
          "data": {
            "type": "object"
          }
        },
        "required": ["provider", "schema", "extractedAt", "data"]
      }
    }
  },
  "required": [
    "connectionId",
    "id",
    "provider",
    "type",
    "timestamp",
    "vehicle",
    "metadata"
  ],
  "discriminator": {
    "propertyName": "type"
  },
  "oneOf": [
    {
      "title": "Engine State Log",
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "engine_state"
        },
        "state": {
          "type": "string",
          "enum": ["on", "off", "idle"]
        }
      },
      "required": ["type", "state"]
    },
    {
      "title": "Odometer Log",
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "odometer"
        },
        "odometer": {
          "title": "Distance In Kilometers",
          "type": "number",
          "format": "double",
          "description": "Distance in kilometers"
        }
      },
      "required": ["type", "odometer"]
    },
    {
      "title": "Total Fuel Consumption Log",
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "total_fuel_consumption"
        },
        "fuelConsumed": {
          "title": "Volume In Liters",
          "type": "number",
          "description": "Volume in liters rounded to 2 decimal places."
        }
      },
      "required": ["type", "fuelConsumed"]
    },
    {
      "title": "Fuel Level Log",
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "fuel_level"
        },
        "fuelPercentage": {
          "title": "Fuel Percentage",
          "type": "number",
          "minimum": 0,
          "maximum": 100,
          "description": "The percentage value of how much fuel is left in the tank."
        }
      },
      "required": ["type", "fuelPercentage"]
    },
    {
      "title": "Engine Runtime Log",
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "engine_runtime"
        },
        "duration": {
          "title": "DurationInMS",
          "type": "integer",
          "description": "Duration in MS"
        }
      },
      "required": ["type", "duration"]
    },
    {
      "title": "Engine Oil Percentage Log",
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "engine_oil_percentage"
        },
        "percentage": {
          "title": "Percentage",
          "type": "number",
          "description": "Percentage value between 0 and 100, rounded to 2 decimal places.",
          "minimum": 0,
          "maximum": 100
        }
      },
      "required": ["type", "percentage"]
    },
    {
      "title": "Engine Oil Pressure Log",
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "engine_oil_pressure"
        },
        "pressure": {
          "title": "Pressure In PSI",
          "type": "number",
          "description": "Pressure in PSI (Pounds per Square Inch) rounded to 2 decimal places."
        }
      },
      "required": ["type", "pressure"]
    },
    {
      "title": "Engine Oil Temperature Log",
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "engine_oil_temperature"
        },
        "temperature": {
          "title": "Temperature In Celsius",
          "type": "number",
          "description": "Temperature in Celsius rounded to 2 decimal places."
        }
      },
      "required": ["type", "temperature"]
    },
    {
      "title": "Engine Coolant Temperature Log",
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "engine_coolant_temperature"
        },
        "temperature": {
          "title": "Temperature In Celsius",
          "type": "number",
          "description": "Temperature in Celsius rounded to 2 decimal places."
        }
      },
      "required": ["type", "temperature"]
    },
    {
      "title": "Coolant Percentage Log",
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "coolant_percentage"
        },
        "percentage": {
          "title": "Percentage",
          "type": "number",
          "description": "Percentage value between 0 and 100, rounded to 2 decimal places.",
          "minimum": 0,
          "maximum": 100
        }
      },
      "required": ["type", "percentage"]
    },
    {
      "title": "Engine RPM Log",
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "engine_rpm"
        },
        "rpm": {
          "title": "RPM",
          "type": "number",
          "description": "Engine RPM (Revolutions Per Minute) rounded to 2 decimal places."
        }
      },
      "required": ["type", "rpm"]
    },
    {
      "title": "Battery Voltage Log",
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "battery_voltage"
        },
        "voltage": {
          "title": "Voltage In Volts",
          "type": "number",
          "description": "Voltage in volts rounded to 2 decimal places."
        }
      },
      "required": ["type", "voltage"]
    }
  ]
}
