---
$schema: "http://json-schema.org/draft-07/schema#"
$id: "https://oimlsmart.org/schemas/R126.yaml"
title: "OIML R126 (Evidential breath analyzers) Certificate Schema"
description: |
  OIML R126:1998 "Evidential breath analyzers". Unlike the weighing and
  flow Recommendations, R126 does not declare a discrete accuracy class
  in `recommendation.accuracy_classes` — accuracy is expressed
  numerically as `measuring_range`, `verification_scale` (resolution),
  and `level_of_disclosure_normal_mode` (display increment).

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: R126 }
      edition:     { type: integer, enum: [1998] }
      amendment:   { type: [integer, "null"] }
      scheme:      { type: string, enum: [A, B] }
      accuracy_classes:
        description: |
          R126 does not define a discrete accuracy class. Always empty
          (declared for schema uniformity with other Recommendations).
        type: array
        items: { type: string }
  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" }
  d011_tests_applicable:
    description: Tests mandated by R126:1998 type evaluation (D 11:2013 subset).
    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_t18_dc_mains_voltage_variation }
    - { test_id: d011_t20_ac_mains_voltage_variation }
    - { test_id: d011_t22_dc_mains_dips_interruptions }
    - { 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_t28_bursts_signal_data_control }
    - { test_id: d011_t29_surges_signal_data_control }
    - { test_id: d011_t33_rf_em_fields_general }
    - { test_id: d011_t35_electrostatic_discharges }

definitions:
  CertifiedType:
    type: object
    required: [category, type_designations]
    properties:
      category:
        type: string
        enum:
        - Evidential breath analyzer
        - Evidential breath analyser
        - Evidential breath analyzers
        - Evidential Breath Analyzer
        - Evidential Breath Analyser
        - Evidential breath analyzer (alcohol)
      type_designations:
        type: array
        minItems: 1
        items: { type: string }
      module_designation:
        description: |
          R126 instruments may be fixed-mount, portable, or handheld.
          Free-text in the corpus; not a closed enum.
        type: [string, "null"]
      description: { type: string }

  Characteristics:
    type: object
    properties:
      type_level: { $ref: "#/definitions/TypeLevel" }
      model_level:
        type: array
        items: { $ref: "#/definitions/ModelLevelEntry" }
      config_level:
        type: array
        items: { $ref: "#/definitions/ConfigLevelEntry" }

  TypeLevel:
    type: object
    properties:
      # Measuring parameters (no OIML accuracy class)
      measuring_range:                    { $ref: "_core.yaml#/definitions/StructuredValue" }
      scale_interval:                     { $ref: "_core.yaml#/definitions/StructuredValue" }
      verification_scale:                 { $ref: "_core.yaml#/definitions/StructuredValue" }
      verification_step:                  { $ref: "_core.yaml#/definitions/StructuredValue" }
      indication_step_normal:             { $ref: "_core.yaml#/definitions/StructuredValue" }
      indication_scale_normal:            { $ref: "_core.yaml#/definitions/StructuredValue" }
      level_of_disclosure_normal_mode:     { $ref: "_core.yaml#/definitions/StructuredValue" }
      # Environmental
      temperature_range:                  { $ref: "_modules/d011_environmental.yaml#/definitions/TemperatureRange" }
      storage_temperature_range:          { $ref: "_core.yaml#/definitions/StructuredValue" }
      humidity_class:                     { $ref: "_modules/d011_environmental.yaml#/definitions/ClimaticClass" }
      electromagnetic_environment_class:  { $ref: "_modules/d011_environmental.yaml#/definitions/EMClass" }
      mechanical_environment_class:       { $ref: "_modules/d011_environmental.yaml#/definitions/MechanicalClass" }
      # Warm-up / time-to-operate
      warm_up_time:                       { $ref: "_core.yaml#/definitions/StructuredValue" }
      max_warm_up_time_after_power_on:    { $ref: "_core.yaml#/definitions/StructuredValue" }
      max_warm_up_time_from_standby:      { $ref: "_core.yaml#/definitions/StructuredValue" }
      time_to_operate_after_power_on:     { $ref: "_core.yaml#/definitions/StructuredValue" }
      time_to_operate_from_standby:       { $ref: "_core.yaml#/definitions/StructuredValue" }
      power_on_time:                      { $ref: "_core.yaml#/definitions/StructuredValue" }
      standby_to_operational_time:        { $ref: "_core.yaml#/definitions/StructuredValue" }
      max_time_after_power_on:            { $ref: "_core.yaml#/definitions/StructuredValue" }
      max_time_from_standby:              { $ref: "_core.yaml#/definitions/StructuredValue" }
      # Power
      power_supply_voltage:               { $ref: "_core.yaml#/definitions/StructuredValue" }
      power_supply_frequency:             { $ref: "_core.yaml#/definitions/StructuredValue" }
      power_supply_type:                  { $ref: "_core.yaml#/definitions/StructuredValue" }
      power_supply_battery:               { $ref: "_core.yaml#/definitions/StructuredValue" }
      battery_power:                      { $ref: "_core.yaml#/definitions/StructuredValue" }
      charger_input_voltage:              { $ref: "_core.yaml#/definitions/StructuredValue" }
      charger_input_frequency:            { $ref: "_core.yaml#/definitions/StructuredValue" }
      charger_output_voltage:             { $ref: "_core.yaml#/definitions/StructuredValue" }
      charger_output_power:               { $ref: "_core.yaml#/definitions/StructuredValue" }
      # Software
      software_identification:            { $ref: "_core.yaml#/definitions/SoftwareIdentification" }

  ModelLevelEntry:
    type: object
    required: [attribute, values]
    properties:
      attribute: { type: string }
      unit:
        $ref: "_units.yaml#/definitions/Unit"
      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:
        $ref: "_units.yaml#/definitions/Unit"
      values:
        type: array
        items:
          type: object
          required: [condition, value]
          properties:
            condition: { type: string }
            value:     { $ref: "_core.yaml#/definitions/ValueOrScalar" }

  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 }

allOf:
- description: |
    D 11 §9.2 damp-heat tests apply per humidity class:
    H2 → t08 (steady state); H3 → t09 (cyclic).
  if:
    properties:
      characteristics:
        properties:
          type_level:
            properties:
              humidity_class:
                properties:
                  value: { const: H2 }
  then:
    properties:
      d011_tests_applicable:
        contains: { properties: { test_id: { const: d011_t08_damp_heat_steady_state } } }
- if:
    properties:
      characteristics:
        properties:
          type_level:
            properties:
              humidity_class:
                properties:
                  value: { const: H3 }
  then:
    properties:
      d011_tests_applicable:
        contains: { properties: { test_id: { const: d011_t09_damp_heat_cyclic } } }
