---

#
# JSON Schema definition for tmt `results.yaml` file
#
# https://tmt.readthedocs.io/en/stable/spec/plans.html#execute
#

$id: /schemas/results
$schema: https://json-schema.org/draft-07/schema

definitions:
  duration:
    type: string
    pattern: "^[0-9]{2,}:[0-5][0-9]:[0-5][0-9]$"

  check_result:
    type: object
    properties:
      name:
        type: string

      event:
        type: string
        enum:
          - "before-test"
          - "after-test"

      result:
        $ref: "/schemas/common#/definitions/result_outcome"

      original-result:
        $ref: "/schemas/common#/definitions/result_outcome"

      note:
        $ref: "/schemas/common#/definitions/result_note"

      log:
        $ref: "/schemas/common#/definitions/result_log"

      start-time:
        $ref: "/schemas/common#/definitions/timestamp"

      end-time:
        $ref: "/schemas/common#/definitions/timestamp"

      duration:
        $ref: "#/definitions/duration"

    required:
      - name
      - event
      - result

  check_results:
    type: array
    items:
      $ref: "#/definitions/check_result"

  subresult:
    type: object
    properties:
      name:
        type: string

      result:
        $ref: "/schemas/common#/definitions/result_outcome"

      original-result:
        $ref: "/schemas/common#/definitions/result_outcome"

      note:
        $ref: "/schemas/common#/definitions/result_note"

      log:
        $ref: "/schemas/common#/definitions/result_log"

      start-time:
        $ref: "/schemas/common#/definitions/timestamp"

      end-time:
        $ref: "/schemas/common#/definitions/timestamp"

      duration:
        $ref: "#/definitions/duration"

      check:
        $ref: "#/definitions/check_results"

    required:
      - name
      - result

  subresults:
    type: array
    items:
      $ref: "#/definitions/subresult"

type: array
items:
  type: object
  additionalProperties: false

  properties:
    guest:
      type: object
      additionalProperties: false

      properties:
        name:
          type: string

        role:
          $ref: "/schemas/common#/definitions/role"

      required: []
      minProperties: 1

    name:
      type: string
      pattern: "^/.*"

    serial-number:
      type: integer

    web-link:
      oneOf:
        - type: "null"
        - type: string
          format: uri

    result:
      $ref: "/schemas/common#/definitions/result_outcome"

    original-result:
      $ref: "/schemas/common#/definitions/result_outcome"

    context:
      $ref: "/schemas/common#/definitions/context"

    note:
      $ref: "/schemas/common#/definitions/result_note"

    start-time:
      $ref: "/schemas/common#/definitions/timestamp"

    end-time:
      $ref: "/schemas/common#/definitions/timestamp"

    duration:
      $ref: "#/definitions/duration"

    data-path:
      type: string

    ids:
      type: object
      patternProperties:
        ^.*$:
          type: string

    log:
      $ref: "/schemas/common#/definitions/result_log"

    check:
      $ref: "#/definitions/check_results"

    subresult:
      $ref: "#/definitions/subresults"

  required:
    - name
    - result
