---
$schema: "http://json-schema.org/draft-07/schema#"
$id: "https://oimlsmart.org/schemas/R99.yaml"
title: "OIML R99 (Breath Analyzers / Exhaust Gas Analyzers) Certificate Schema"
description: |
  OIML R99 "Breath analyzers" — evidential breath and exhaust gas analyzers.
  The 2008 edition covers vehicle exhaust gas analyzers (category
  "Exhaust Gas Analyzer") and evidential breath testers; accuracy classes
  00 / 0 / I / II per R99-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: R99 }
      edition:     { type: integer, enum: [2000, 2008] }
      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 R99 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_t11_atmospheric_pressure }
    - { test_id: d011_t20_ac_mains_voltage_variation }
    - { test_id: d011_t21_ac_mains_frequency_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_t30_mains_power_frequency_em_field }
    - { test_id: d011_t33_rf_em_fields_general }
    - { test_id: d011_t35_electrostatic_discharges }

definitions:
  AccuracyClass:
    description: |
      OIML R99-1 §3.2 accuracy class. The 1998/2008 scheme uses four nominal-accuracy
      indices "00", "0", "I", "II". The "0/I" combined token appears in older
      certificates bridging the 1998 and 2008 editions.
    allOf:
    - $ref: "_core.yaml#/definitions/StructuredValue"
    - properties:
        value:
          type: [string, "null"]
          oneOf:
          - const: "00"
            description: Class 00 — highest accuracy, used for Type Approval
          - const: "0"
            description: Class 0 — high accuracy
          - const: "0/I"
            description: Combined class 0 or I (legacy / bridging editions)
          - const: "I"
            description: Class I — medium accuracy
          - const: "II"
            description: Class II — service-grade accuracy

  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:                          { $ref: "#/definitions/AccuracyClass" }
          minimal_flow:                            { $ref: "_core.yaml#/definitions/StructuredValue" }
          warm_up_time:                            { $ref: "_core.yaml#/definitions/StructuredValue" }
          adjustment_period:                       { $ref: "_core.yaml#/definitions/StructuredValue" }
          climatic_environment_intended_location:  { $ref: "_core.yaml#/definitions/StructuredValue" }
          power_supply_voltage:                    { $ref: "_core.yaml#/definitions/StructuredValue" }
          power_supply_frequency:                  { $ref: "_core.yaml#/definitions/StructuredValue" }
          power_supply_type:                       { $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_environment_class:       { $ref: "_modules/d011_environmental.yaml#/definitions/EMClass" }
          mechanical_environment_class:            { $ref: "_modules/d011_environmental.yaml#/definitions/MechanicalClass" }
      model_level:
        type: array
        description: |
          R99 reports gas measurement ranges per single instrument model. While the
          dataset uses `model_level` with one row per model, R99 analyzers typically
          have a single model per cert — these could be flattened into `type_level`.
        items: { $ref: "#/definitions/ModelLevelEntry" }
      config_level:
        type: array
        items: { $ref: "#/definitions/ConfigLevelEntry" }

  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. gas range tables).
    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 }
