---
$schema: "http://json-schema.org/draft-07/schema#"
$id: "https://oimlsmart.org/schemas/R106.yaml"
title: "OIML R106 (Automatic Rail-Weighbridges) Certificate Schema"
description: |
  OIML R106 "Automatic rail-weighbridges". Covers coupled-wagon, train-mass and
  single-wagon weighing. Two parallel accuracy-class vocabularies exist in
  source PDFs (DK2: coupled_wagon_weighing + total_train_weighing; NL1:
  wagon_mass + train_mass); both register the same numeric class set
  0.5 / 1 / 2 per R106-1 §3.2.
type: object
required: [certificate, certified_type, characteristics, recommendation]
properties:
  certificate:           { $ref: "_core.yaml#/definitions/Certificate" }
  issuing_authority:     { $ref: "_core.yaml#/definitions/IssuingAuthority" }
  applicants:            { $ref: "_core.yaml#/definitions/PartyList" }
  manufacturers:         { $ref: "_core.yaml#/definitions/PartyList" }
  certified_type:        { $ref: "#/definitions/CertifiedType" }
  characteristics:       { $ref: "#/definitions/Characteristics" }
  recommendation:
    type: object
    required: [id, edition, scheme]
    properties:
      id:          { type: string, const: R106 }
      edition:     { type: integer, enum: [2011] }
      amendment:   { type: [string, integer, "null"] }
      scheme:      { type: string, enum: [A, B] }
      accuracy_classes:
        type: array
        items:
          oneOf:
          - type: string
          - type: number
          - $ref: "#/definitions/AccuracyClass"
  test_reports:          { $ref: "_core.yaml#/definitions/TestReportList" }
  revision_history:      { $ref: "_core.yaml#/definitions/RevisionHistory" }
  model_family:          { $ref: "_core.yaml#/definitions/ModelFamily" }
  components:
    type: array
    items: { $ref: "_core.yaml#/definitions/Component" }
  footnotes:             { $ref: "_core.yaml#/definitions/FootnoteList" }
  matrix_tables:         { $ref: "#/definitions/MatrixTableList" }
  d011_tests_applicable:
    description: Tests mandated by R106-2 type evaluation.
    type: array
    items: { $ref: "#/definitions/D011TestReference" }
    default:
    - { test_id: d011_t06_static_temperature }
    - { test_id: d011_t07_static_temperature }
    - { test_id: d011_t08_damp_heat_steady_state }
    - { test_id: d011_t09_damp_heat_cyclic }
    - { test_id: d011_t11_atmospheric_pressure }
    - { test_id: d011_t15_vibration_random }
    - { test_id: d011_t16_vibration_sinusoidal }
    - { test_id: d011_t17_mechanical_shock }
    - { test_id: d011_t20_ac_mains_voltage_variation }
    - { test_id: d011_t23_ac_mains_dips_interruptions }
    - { test_id: d011_t26_bursts_ac_dc_mains }
    - { test_id: d011_t27_surges_ac_dc_mains }
    - { test_id: d011_t33_rf_em_fields_general }
    - { test_id: d011_t35_electrostatic_discharges }

definitions:
  AccuracyClass:
    description: |
      OIML R106-1 §3.2 rail-weighbridge accuracy class. A single instrument
      may be certified for several classes applied to different weighing modes
      (coupled wagon / total train).
    allOf:
    - $ref: "_core.yaml#/definitions/StructuredValue"
    - properties:
        value:
          oneOf:
          - type: [string, "null"]
            oneOf:
            - const: "0.5"
              description: Class 0.5 — highest precision
            - const: "1"
              description: Class 1 — medium-high precision
            - const: "2"
              description: Class 2 — medium precision
            - const: "N/A"
              description: Not applicable
          - type: number
            description: Numeric form of class identifier
          - type: array
            minItems: 1
            items:
              oneOf:
              - type: string
              - type: number
            description: Array of class identifiers (multi-class certificate)

  AccuracyClassCoupledWagonWeighing:
    description: R106 DK2 issuer class for coupled wagon weighing mode.
    allOf:
    - $ref: "#/definitions/AccuracyClass"

  AccuracyClassTotalTrainWeighing:
    description: R106 DK2 issuer class for total train weighing mode.
    allOf:
    - $ref: "#/definitions/AccuracyClass"

  AccuracyClassWagonMass:
    description: R106 NL1 issuer class for wagon mass weighing (single wagon).
    allOf:
    - $ref: "#/definitions/AccuracyClass"

  AccuracyClassTrainMass:
    description: R106 NL1 issuer class for train mass weighing (total train).
    allOf:
    - $ref: "#/definitions/AccuracyClass"

  ElectromagneticClassification:
    description: |
      R106-1 §3.x EM classification. DK2 uses the term "electromagnetic_classification"
      while NL1 uses "electromagnetic_environment_class"; both refer to D 11 §7.4
      E1/E2/E3 classes.
    allOf:
    - $ref: "_modules/d011_environmental.yaml#/definitions/EMClass"

  CertifiedType:
    type: object
    required: [category, type_designations]
    properties:
      category: { type: string }
      type_designations:
        type: array
        minItems: 1
        items: { type: string }
      module_designation: { type: [string, "null"] }
      description: { type: [string, "null"] }

  Characteristics:
    type: object
    properties:
      type_level:
        type: object
        additionalProperties: { $ref: "_core.yaml#/definitions/StructuredValue" }
        properties:
          accuracy_class_coupled_wagon_weighing:           { $ref: "#/definitions/AccuracyClassCoupledWagonWeighing" }
          accuracy_class_total_train_weighing:             { $ref: "#/definitions/AccuracyClassTotalTrainWeighing" }
          accuracy_class_wagon_mass:                       { $ref: "#/definitions/AccuracyClassWagonMass" }
          accuracy_class_train_mass:                       { $ref: "#/definitions/AccuracyClassTrainMass" }
          maximum_wagon_weight:                            { $ref: "_core.yaml#/definitions/StructuredValue" }
          maximum_wagon_mass:                              { $ref: "_core.yaml#/definitions/StructuredValue" }
          minimum_wagon_weight:                            { $ref: "_core.yaml#/definitions/StructuredValue" }
          minimum_wagon_mass:                              { $ref: "_core.yaml#/definitions/StructuredValue" }
          minimum_capacity:                                { $ref: "_core.yaml#/definitions/StructuredValue" }
          maximum_capacity:                                { $ref: "_core.yaml#/definitions/StructuredValue" }
          scale_interval:                                  { $ref: "_core.yaml#/definitions/StructuredValue" }
          transducer_type:                                 { $ref: "_core.yaml#/definitions/StructuredValue" }
          max_no_of_weighline_transducers:                 { $ref: "_core.yaml#/definitions/StructuredValue" }
          max_number_and_type_of_wagons_per_train:         { $ref: "_core.yaml#/definitions/StructuredValue" }
          maximum_number_of_wagons_per_train:              { $ref: "_core.yaml#/definitions/StructuredValue" }
          minimum_number_of_wagons_per_train:              { $ref: "_core.yaml#/definitions/StructuredValue" }
          direction_of_weighing:                           { $ref: "_core.yaml#/definitions/StructuredValue" }
          maximum_speed:                                   { $ref: "_core.yaml#/definitions/StructuredValue" }
          minimum_speed:                                   { $ref: "_core.yaml#/definitions/StructuredValue" }
          weighing_methods:                                { $ref: "_core.yaml#/definitions/StructuredValue" }
          application:                                     { $ref: "_core.yaml#/definitions/StructuredValue" }
          wagons_pushed_pulled:                            { $ref: "_core.yaml#/definitions/StructuredValue" }
          wagons_coupled_uncoupled:                        { $ref: "_core.yaml#/definitions/StructuredValue" }
          climatic_environment_location:                   { $ref: "_core.yaml#/definitions/StructuredValue" }
          climatic_environment_temperature_range_indicator:        { $ref: "#/definitions/ClimaticIndicatorTempRange" }
          climatic_environment_temperature_range_mechanical_assembly: { $ref: "#/definitions/ClimaticMechanicalTempRange" }
          software_identification_firmware_version:        { $ref: "_core.yaml#/definitions/StructuredValue" }
          software_identification_firmware_checksum:       { $ref: "_core.yaml#/definitions/StructuredValue" }
          software_identification_gui_version:             { $ref: "_core.yaml#/definitions/StructuredValue" }
          firmware_version:                                { $ref: "_core.yaml#/definitions/StructuredValue" }
          firmware_checksum:                               { $ref: "_core.yaml#/definitions/StructuredValue" }
          gui_version:                                     { $ref: "_core.yaml#/definitions/StructuredValue" }
          software_identification:                         { $ref: "_core.yaml#/definitions/SoftwareIdentification" }
          temperature_range:                               { $ref: "_modules/d011_environmental.yaml#/definitions/TemperatureRange" }
          humidity_class:                                  { $ref: "_modules/d011_environmental.yaml#/definitions/ClimaticClass" }
          electromagnetic_classification:                  { $ref: "#/definitions/ElectromagneticClassification" }
          electromagnetic_environment_class:               { $ref: "_modules/d011_environmental.yaml#/definitions/EMClass" }
          mechanical_environment_class:                    { $ref: "_modules/d011_environmental.yaml#/definitions/MechanicalClass" }
          power_supply_voltage:                            { $ref: "_core.yaml#/definitions/StructuredValue" }
          power_supply_frequency:                          { $ref: "_core.yaml#/definitions/StructuredValue" }
          power_supply_type:                               { $ref: "_core.yaml#/definitions/StructuredValue" }
      model_level:
        type: array
        items: { $ref: "#/definitions/ModelLevelEntry" }
      config_level:
        type: array
        description: |
          R106 NL1 certs use config_level to model per-assembly (Indicator vs.
          Mechanical assembly with load cell) humidity/location/temperature ranges.
        items: { $ref: "#/definitions/ConfigLevelEntry" }

  ClimaticIndicatorTempRange:
    description: Per-assembly temperature range for the indicator sub-unit.
    allOf:
    - $ref: "_modules/d011_environmental.yaml#/definitions/TemperatureRange"

  ClimaticMechanicalTempRange:
    description: Per-assembly temperature range for the mechanical (load-cell) sub-unit.
    allOf:
    - $ref: "_modules/d011_environmental.yaml#/definitions/TemperatureRange"

  ModelLevelEntry:
    type: object
    required: [attribute, values]
    properties:
      attribute: { type: string }
      unit_symbol: { type: [string, "null"] }
      unit_id:    { type: [string, "null"] }
      values:
        type: array
        items:
          type: object
          required: [model, value]
          properties:
            model:            { type: string }
            value:            { $ref: "_core.yaml#/definitions/ValueOrScalar" }
            footnote_markers:
              type: array
              items: { type: string }

  ConfigLevelEntry:
    type: object
    required: [attribute, axis, values]
    properties:
      attribute: { type: string }
      axis:      { oneOf: [ { type: string }, { type: "null" } ] }
      unit_symbol: { type: [string, "null"] }
      unit_id:    { type: [string, "null"] }
      values:
        type: array
        items:
          type: object
          required: [condition, value]
          properties:
            condition: { type: string }
            value:     { $ref: "_core.yaml#/definitions/ValueOrScalar" }

  MatrixTableList:
    description: Preserved structured tables (e.g. measurement-range matrices).
    type: array
    items:
      type: object
      required: [name, columns, rows]
      properties:
        name:        { type: string }
        description: { type: [string, "null"] }
        columns:
          type: array
          items: { type: string }
        rows:
          type: array
          items:
            type: object
            additionalProperties: true
        footnotes:
          type: array
          items: { type: string }

  D011TestReference:
    description: Reference to an OIML D 11:2013 performance test.
    type: object
    required: [test_id]
    properties:
      test_id:          { type: string, pattern: '^d011_t\d{2}_' }
      test_level_index: { type: integer, minimum: 1, maximum: 5 }
      notes:            { type: string }
