{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/Fujio-Turner/mobile_field_service/docs/schema/tracking.json",
  "title": "field.tracking",
  "type": "object",
  "additionalProperties": false,
  "required": ["type", "audit", "employeeId", "day", "thresholdM", "capped", "tracking", "expiresAt"],
  "properties": {
    "type": { "const": "tracking" },
    "audit": { "$ref": "#/$defs/audit" },
    "employeeId": { "type": "string", "minLength": 1, "pattern": "^[^:]+$" },
    "email": { "type": "string", "format": "email" },
    "day": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$" },
    "thresholdM": { "type": "number", "exclusiveMinimum": 0 },
    "last": {
      "oneOf": [
        { "type": "null" },
        {
          "type": "array",
          "minItems": 3,
          "maxItems": 3,
          "prefixItems": [
            { "type": "number", "minimum": -90, "maximum": 90 },
            { "type": "number", "minimum": -180, "maximum": 180 },
            { "$ref": "#/$defs/unixSeconds" }
          ]
        }
      ]
    },
    "capped": { "type": "boolean" },
    "pointCount": { "type": "integer", "minimum": 0, "maximum": 4000 },
    "expiresAt": {
      "$ref": "#/$defs/unixSeconds",
      "description": "Local midnight of day + 30 calendar days"
    },
    "tracking": {
      "type": "object",
      "maxProperties": 4000,
      "additionalProperties": {
        "type": "array",
        "minItems": 2,
        "maxItems": 2,
        "prefixItems": [
          { "type": "number", "minimum": -90, "maximum": 90 },
          { "type": "number", "minimum": -180, "maximum": 180 }
        ]
      },
      "propertyNames": { "type": "string", "pattern": "^[0-9]+$" }
    }
  },
  "$defs": {
    "unixSeconds": { "type": "integer", "minimum": 0 },
    "auditStamp": {
      "type": "object",
      "additionalProperties": false,
      "required": ["dt", "ver", "by"],
      "properties": {
        "dt": { "$ref": "#/$defs/unixSeconds" },
        "ver": { "type": "string" },
        "by": { "type": "string" }
      }
    },
    "audit": {
      "type": "object",
      "additionalProperties": false,
      "required": ["cr", "up"],
      "properties": {
        "cr": { "$ref": "#/$defs/auditStamp" },
        "up": { "$ref": "#/$defs/auditStamp" }
      }
    }
  }
}
