{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://w3id.org/materica/schema/0.1/read_request.json",
  "$comment": "Hand-edited. The package's typed shapes are generated from it.",
  "title": "ReadRequest",
  "description": "read_side_contract.md section 1. A reader checks a request member by member at step 0, refusing with reasons, and ignores a member not named here, at any depth.",
  "type": "object",
  "required": ["target", "requirement"],
  "properties": {
    "target": {"$ref": "#/$defs/target"},
    "operating_conditions": {
      "type": "object",
      "additionalProperties": {"$ref": "#/$defs/operating_condition"}
    },
    "requirement": {"$ref": "#/$defs/requirement"},
    "acceptances": {"type": "array", "items": {"$ref": "#/$defs/acceptance"}}
  },
  "$defs": {
    "target": {"oneOf": [{"$ref": "#/$defs/record_target"}, {"$ref": "#/$defs/region_target"}]},
    "record_target": {
      "type": "object",
      "required": ["record", "field"],
      "properties": {"record": {"$ref": "#/$defs/material_ref"}, "field": {"$ref": "#/$defs/field_name"}},
      "not": {"required": ["region"]}
    },
    "region_target": {
      "description": "A region of a scene (geometry.md).",
      "type": "object",
      "required": ["region", "field"],
      "properties": {"region": {"type": "string"}, "field": {"$ref": "#/$defs/field_name"}},
      "not": {"required": ["record"]}
    },
    "material_ref": {
      "description": "A material reference: a record's id and version, and its content hash as the pin.",
      "type": "object",
      "required": ["id", "version", "content_hash"],
      "properties": {
        "id": {"type": "string"},
        "version": {"type": "string"},
        "content_hash": {"type": "string"}
      }
    },
    "field_name": {"type": "string", "pattern": "^[a-z0-9_]+\\.[a-z0-9_]+(?![\\s\\S])"},
    "operating_condition": {"oneOf": [{"$ref": "#/$defs/operating_value"}, {"$ref": "#/$defs/operating_range"}]},
    "operating_value": {
      "type": "object",
      "required": ["value", "unit"],
      "properties": {"value": {"type": "number"}, "unit": {"type": "string"}},
      "not": {"required": ["range"]}
    },
    "operating_range": {
      "description": "[lo, hi], lo not above hi.",
      "type": "object",
      "required": ["range", "unit"],
      "properties": {
        "range": {
          "type": "array",
          "prefixItems": [{"type": "number"}, {"type": "number"}],
          "minItems": 2,
          "maxItems": 2
        },
        "unit": {"type": "string"}
      },
      "not": {"required": ["value"]}
    },
    "requirement": {
      "type": "object",
      "required": ["want"],
      "properties": {
        "want": {"$ref": "#/$defs/want"},
        "conditions": {
          "type": "object",
          "additionalProperties": {"$ref": "#/$defs/requirement_condition"}
        }
      }
    },
    "want": {
      "description": "read_side_contract.md section 6. reference_data, fit and coverage belong to the fits and reference data suite.",
      "enum": ["value", "bounds", "components", "evidence", "reference_data", "fit", "coverage"]
    },
    "requirement_condition": {
      "description": "A tolerance for a numeric condition, an accept list for a token condition (provenance.md section 6.1).",
      "oneOf": [{"$ref": "#/$defs/tolerance_requirement"}, {"$ref": "#/$defs/accept_requirement"}]
    },
    "tolerance_requirement": {
      "type": "object",
      "required": ["tolerance"],
      "properties": {"tolerance": {"$ref": "#/$defs/tolerance"}},
      "not": {"required": ["accept"]}
    },
    "tolerance": {
      "description": "Absolute, in the condition's registered unit.",
      "type": "object",
      "required": ["value", "unit"],
      "properties": {"value": {"type": "number", "minimum": 0}, "unit": {"type": "string"}}
    },
    "accept_requirement": {
      "type": "object",
      "required": ["accept"],
      "properties": {"accept": {"type": "array", "items": {"type": "string"}}},
      "not": {"required": ["tolerance"]}
    },
    "acceptance": {
      "description": "An acceptance of a kind a read takes (read_side_contract.md section 1; declarations.md section 4.1). An acceptance of any other kind, or one that breaks its shape, refuses the request.",
      "oneOf": [
        {"$ref": "#/$defs/nominal_acceptance"},
        {"$ref": "#/$defs/implied_condition_acceptance"},
        {"$ref": "#/$defs/extrapolation_acceptance"},
        {"$ref": "#/$defs/pick_or_overlay"}
      ]
    },
    "acceptance_members": {
      "description": "What every acceptance holds beside its kind's own members (declarations.md section 4.1): the field it names, checked as a target's is; and where it applies, its record, region or interval. A read applies one only to a read of the field it names, at its own record: one located at a region, at an interval or nowhere is checked and not applied, and step 0 does not check a location's shape. A read ignores its reason and basis.",
      "type": "object",
      "required": ["field"],
      "properties": {
        "record": {"$ref": "record.writer.json#/$defs/json_value", "description": "The record it applies at, by id, version and content_hash, the members of a material reference."},
        "region": {"$ref": "record.writer.json#/$defs/json_value", "description": "A region of a scene (geometry.md)."},
        "interval": {"$ref": "record.writer.json#/$defs/json_value", "description": "An interval of a layered path (geometry.md), which no request targets."},
        "field": {"$ref": "#/$defs/field_name"},
        "reason": {"$ref": "record.writer.json#/$defs/json_value", "description": "Why the consumer declares it; a read ignores it."},
        "basis": {"$ref": "record.writer.json#/$defs/json_value", "description": "What it rests on; a read ignores it."}
      }
    },
    "pick_or_overlay": {
      "description": "A pick or an overlay (declarations.md section 4.1). Their own members are written with the steps that apply them, with alternatives and overlays.",
      "type": "object",
      "allOf": [{"$ref": "#/$defs/acceptance_members"}],
      "required": ["acceptance"],
      "properties": {"acceptance": {"enum": ["pick", "overlay"]}}
    },
    "extrapolation_acceptance": {
      "description": "How the consumer computes a value outside a form's range, from the end value a read under it returns (declarations.md section 4.1). A read applies it only under want value, outside the readable range, at no declared edge and across none (read_side_contract.md section 5).",
      "type": "object",
      "allOf": [{"$ref": "#/$defs/acceptance_members"}],
      "required": ["acceptance", "method", "law"],
      "properties": {
        "acceptance": {"const": "extrapolation"},
        "method": {"$ref": "vocabulary/acceptances.json#/$defs/extrapolation_method"},
        "law": {"description": "Text of at least one character, which a reader does not judge: white space alone is accepted.", "type": "string", "minLength": 1}
      }
    },
    "nominal_acceptance": {
      "description": "A value for an interval, in the field's registered unit. A parameter set's nominal holds params in place of a value; no field of this version takes a parameter set, and a read ignores params.",
      "type": "object",
      "allOf": [{"$ref": "#/$defs/acceptance_members"}],
      "required": ["acceptance", "value"],
      "properties": {
        "acceptance": {"const": "nominal"},
        "value": {"type": "number"},
        "params": {"$ref": "record.writer.json#/$defs/json_value", "description": "A parameter set's nominal vector (model_families.md)."}
      }
    },
    "implied_condition_acceptance": {
      "description": "A value for each condition in implies, which fills a condition the record holds as unstated or does not hold, on a field whose specimen states the fact and its token.",
      "type": "object",
      "allOf": [{"$ref": "#/$defs/acceptance_members"}],
      "required": ["acceptance", "fact", "token", "implies"],
      "properties": {
        "acceptance": {"const": "implied_condition"},
        "fact": {"description": "A specimen fact whose shape has a token member.", "type": "string"},
        "token": {"description": "One of that fact's tokens.", "type": "string"},
        "implies": {
          "description": "Per registered condition, a record condition's shape of that condition's kind without basis, plus_minus or set_or_measured, and never a status object: a numeric condition's holds no token, and a token condition's no value, range or unit (read_side_contract.md section 1).",
          "type": "object",
          "additionalProperties": {"$ref": "#/$defs/implies_value"}
        }
      }
    },
    "implies_value": {
      "description": "A value or a range with its unit, in the condition's registered unit, for a numeric condition; a token of its row for a token condition.",
      "anyOf": [{"$ref": "#/$defs/operating_condition"}, {"$ref": "#/$defs/implies_token"}]
    },
    "implies_token": {
      "type": "object",
      "required": ["token"],
      "properties": {"token": {"type": "string"}}
    }
  }
}
