{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://schemas.ruter.no/adt/ota/api/v3.0/pe/sales/diagnostics/sales-diagnostics.json",
  "type": "object",
  "title": "SalesDiagnostics",
  "required": [
    "eventTimestamp",
    "traceId",
    "metrics",
    "context"
  ],
  "additionalProperties": true,
  "properties": {
    "eventTimestamp": {
      "$id": "#/properties/eventTimestamp",
      "type": "string",
      "description": "Time of diagnostics generated",
      "format": "date-time"
    },
    "traceId": {
      "$id": "#/properties/traceId",
      "$comment": "Added in version 2.5",
      "type": "string",
      "description": "A unique identifier to be able to trace this message. Also used to detect duplicate messages received."
    },
    "spanId": {
      "$id": "#/properties/spanId",
      "type": "string",
      "description": "A unique identifier for an individual step of a transaction. Consists of the spanId from the current_stop message and a new UUID for this step, separated by a colon."
    },
    "metrics": {
      "$id": "#/properties/metrics",
      "type": "object",
      "description": "Contains measurable diagnostics fields",
      "required": [
        "nfcStatus",
        "printerStatus",
        "internetConnectionStatus",
        "loggedIn"
      ],
      "additionalProperties": true,
      "properties": {
        "nfcStatus": {
          "$id": "#/properties/metrics/properties/nfcStatus",
          "type": "object",
          "description": "NFC connection status",
          "required": [
            "interfaceType",
            "connected"
          ],
          "additionalProperties": true,
          "properties": {
            "interfaceType": {
              "$id": "#/properties/metrics/properties/nfcStatus/properties/interfaceType",
              "type": "string",
              "description": "The interface connection type. Legal values: integrated, usb, mqtt"
            },
            "connected": {
              "$id": "#/properties/metrics/properties/nfcStatus/properties/connected",
              "type": "boolean",
              "description": "Whether or not the NFC device is connected"
            },
            "errorMessage": {
              "$id": "#/properties/metrics/properties/nfcStatus/properties/errorMessage",
              "type": "string",
              "description": "An optional error message if the device is not connected"
            }
          }
        },
        "printerStatus": {
          "$id": "#/properties/metrics/properties/printerStatus",
          "type": "object",
          "description": "Printer connection status",
          "required": [
            "connected"
          ],
          "additionalProperties": true,
          "properties": {
            "connected": {
              "$id": "#/properties/metrics/properties/printerStatus/properties/connected",
              "type": "boolean",
              "description": "Whether or not the printer is connected"
            },
            "errorMessage": {
              "$id": "#/properties/metrics/properties/printerStatus/properties/errorMessage",
              "type": "string",
              "description": "An optional error message if the printer is not connected"
            }
          }
        },
        "internetConnectionStatus": {
          "$id": "#/properties/metrics/properties/internetConnectionStatus",
          "type": "object",
          "description": "Internet connection status",
          "required": [
            "connected"
          ],
          "additionalProperties": true,
          "properties": {
            "connected": {
              "$id": "#/properties/metrics/properties/internetConnectionStatus/properties/connected",
              "type": "boolean",
              "description": "Whether or not the device has a working internet connection"
            },
            "errorMessage": {
              "$id": "#/properties/metrics/properties/internetConnectionStatus/properties/errorMessage",
              "type": "string",
              "description": "An optional error message if the internet connection is down"
            }
          }
        },
        "loggedIn": {
          "$id": "#/properties/metrics/properties/loggedIn",
          "type": "boolean",
          "description": "Whether or not the user is logged in to RuterSalg"
        }
      }
    },
    "context": {
      "$id": "#/properties/context",
      "type": "object",
      "description": "Contains fields with context data",
      "required": [
        "trigger",
        "appVersion"
      ],
      "additionalProperties": true,
      "properties": {
        "journeyRef": {
          "$id": "#/properties/context/properties/journeyRef",
          "type": "string",
          "description": "Last journeyRef obtained by the app"
        },
        "stopPlaceId": {
          "$id": "#/properties/context/properties/stopPlaceId",
          "type": "string",
          "description": "StopPlaceId of the upcoming stop"
        },
        "tariffZone": {
          "$id": "#/properties/context/properties/tariffZone",
          "type": "string",
          "description": "The tariff zone the vehicle is currently in"
        },
        "trigger": {
          "$id": "#/properties/context/properties/trigger",
          "type": "string",
          "description": "The event that triggered the diagnostics msg to be produced. Legal values: Startup, LoginStatusChanged, StopPlace, PrinterStatusChanged, NfcStatusChanged, InternetConnectionStatusChanged, IntegrationTest"
        },
        "appVersion": {
          "$id": "#/properties/context/properties/appVersion",
          "type": "string",
          "description": "Version of the RuterSalg app that sent the message"
        },
        "userId": {
          "$id": "#/properties/context/properties/userId",
          "type": "string",
          "description": "The userId of the logged in user"
        }
      }
    }
  }
}
