{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/Fujio-Turner/mobile_field_service/docs/schema/users.json",
  "title": "field.users",
  "type": "object",
  "additionalProperties": true,
  "required": ["type", "audit", "employeeId", "email", "username", "displayName", "role"],
  "not": {
    "anyOf": [
      { "required": ["password"] },
      { "required": ["hash"] },
      { "required": ["session"] },
      { "required": ["token"] }
    ]
  },
  "properties": {
    "type": { "const": "user" },
    "audit": { "$ref": "#/$defs/audit" },
    "employeeId": { "type": "string", "minLength": 1, "pattern": "^[^:]+$" },
    "email": { "type": "string", "format": "email" },
    "username": { "type": "string", "minLength": 1 },
    "displayName": { "type": "string", "minLength": 1 },
    "role": { "type": "string", "minLength": 1 },
    "workModes": {
      "type": "array",
      "items": { "type": "string", "enum": ["assets", "customer", "sales"] },
      "uniqueItems": true
    },
    "crewId": { "type": "string" },
    "districtId": { "type": "string" },
    "vanId": { "type": "string" },
    "phone": { "type": "string" },
    "active": { "type": "boolean" }
  },
  "$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" }
      }
    }
  }
}
