{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://triumph-alliance.com/schemas/ibipc-master-source-1.0.0.json",
  "title": "IBIPC Master Product Source",
  "type": "object",
  "required": [
    "meta",
    "enums",
    "categories",
    "products",
    "variants",
    "assemblies",
    "materials",
    "evidence",
    "discrepancies",
    "coverage_matrix"
  ],
  "$defs": {
    "param": {
      "type": "object",
      "required": [
        "value",
        "unit",
        "source_type",
        "source_page",
        "source_reference"
      ],
      "properties": {
        "value": {},
        "unit": {
          "type": [
            "string",
            "null"
          ]
        },
        "source_type": {
          "enum": [
            "CATALOG_CONFIRMED",
            "CERTIFICATE_CONFIRMED",
            "TEST_REPORT_CONFIRMED",
            "DERIVED",
            "ESTIMATED",
            "ENGINEER_INPUT",
            "NOT_AVAILABLE",
            "ENGINEER_REVIEW_REQUIRED"
          ]
        },
        "source_page": {
          "type": [
            "integer",
            "null"
          ]
        },
        "source_reference": {
          "type": [
            "string",
            "null"
          ]
        },
        "review_comment_ru": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "value": {
                "type": "null"
              }
            }
          },
          "then": {
            "properties": {
              "source_type": {
                "enum": [
                  "NOT_AVAILABLE",
                  "ENGINEER_REVIEW_REQUIRED"
                ]
              }
            }
          }
        }
      ]
    },
    "node": {
      "type": "object",
      "required": [
        "ref_id",
        "role",
        "qty",
        "qty_source_type",
        "children"
      ],
      "properties": {
        "ref_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "role": {
          "type": "string"
        },
        "qty": {
          "type": [
            "integer",
            "null"
          ]
        },
        "qty_source_type": {
          "enum": [
            "CATALOG_CONFIRMED",
            "CERTIFICATE_CONFIRMED",
            "TEST_REPORT_CONFIRMED",
            "DERIVED",
            "ESTIMATED",
            "ENGINEER_INPUT",
            "NOT_AVAILABLE",
            "ENGINEER_REVIEW_REQUIRED"
          ]
        },
        "children": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/node"
          }
        }
      }
    },
    "dims": {
      "type": "object",
      "required": [
        "length",
        "width",
        "height",
        "thickness",
        "internal_length",
        "internal_width",
        "internal_height",
        "external_length",
        "external_width",
        "external_height"
      ],
      "properties": {
        "length": {
          "$ref": "#/$defs/param"
        },
        "width": {
          "$ref": "#/$defs/param"
        },
        "height": {
          "$ref": "#/$defs/param"
        },
        "thickness": {
          "$ref": "#/$defs/param"
        },
        "internal_length": {
          "$ref": "#/$defs/param"
        },
        "internal_width": {
          "$ref": "#/$defs/param"
        },
        "internal_height": {
          "$ref": "#/$defs/param"
        },
        "external_length": {
          "$ref": "#/$defs/param"
        },
        "external_width": {
          "$ref": "#/$defs/param"
        },
        "external_height": {
          "$ref": "#/$defs/param"
        }
      }
    },
    "eng": {
      "type": "object",
      "required": [
        "volume",
        "mass",
        "material_density",
        "center_of_mass",
        "lifting_points",
        "transport_dimensions",
        "transport_mass",
        "installation_orientation",
        "burial_depth",
        "assembly_time",
        "crew_required"
      ],
      "properties": {
        "volume": {
          "$ref": "#/$defs/param"
        },
        "mass": {
          "$ref": "#/$defs/param"
        },
        "material_density": {
          "$ref": "#/$defs/param"
        },
        "center_of_mass": {
          "$ref": "#/$defs/param"
        },
        "lifting_points": {
          "$ref": "#/$defs/param"
        },
        "transport_dimensions": {
          "$ref": "#/$defs/param"
        },
        "transport_mass": {
          "$ref": "#/$defs/param"
        },
        "installation_orientation": {
          "$ref": "#/$defs/param"
        },
        "burial_depth": {
          "$ref": "#/$defs/param"
        },
        "assembly_time": {
          "$ref": "#/$defs/param"
        },
        "crew_required": {
          "$ref": "#/$defs/param"
        }
      }
    }
  },
  "properties": {
    "products": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "ibipc_id",
          "official_name",
          "normalized_name",
          "category",
          "subcategory",
          "product_type",
          "model_type",
          "geometry_status",
          "source_page",
          "source_pages_all",
          "dimensions",
          "mass",
          "material",
          "protection_data",
          "engineering",
          "model_status",
          "engineer_review_status"
        ],
        "properties": {
          "ibipc_id": {
            "type": "string",
            "pattern": "^IBIPC-[A-Z]{3}-\\d{3}$"
          },
          "model_type": {
            "enum": [
              "EXACT_PARAMETRIC_COMPONENT",
              "EXACT_ASSEMBLY",
              "PARTIAL_ENGINEERING_MODEL",
              "CONCEPT_ENVELOPE_MODEL",
              "MATERIAL_NON_GEOMETRIC",
              "PROJECT_SPECIFIC_TEMPLATE",
              "NO_SOURCE_GEOMETRY_LISTED_ONLY"
            ]
          },
          "geometry_status": {
            "enum": [
              "COMPLETE",
              "PARTIAL",
              "ENVELOPE_ONLY",
              "NONE"
            ]
          },
          "dimensions": {
            "$ref": "#/$defs/dims"
          },
          "mass": {
            "$ref": "#/$defs/param"
          },
          "engineering": {
            "$ref": "#/$defs/eng"
          },
          "material": {
            "type": "array",
            "items": {
              "$ref": "#/$defs/param"
            }
          },
          "configuration": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/$defs/param"
            }
          },
          "protection_data": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "claim_type",
                "text",
                "source_page"
              ],
              "properties": {
                "claim_type": {
                  "enum": [
                    "CATALOG_GENERAL_CLAIM",
                    "PRODUCT_SPECIFIC_CLAIM",
                    "TEST_SPECIFIC_DATA",
                    "CERTIFICATE_SPECIFIC_DATA"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "variants": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "variant_id",
          "parent_id",
          "variant_name",
          "variant_axis",
          "dimensions",
          "mass"
        ],
        "properties": {
          "variant_id": {
            "type": "string",
            "pattern": "^IBIPC-[A-Z]{3}-\\d{3}-[A-Z0-9]+$"
          },
          "dimensions": {
            "$ref": "#/$defs/dims"
          },
          "mass": {
            "$ref": "#/$defs/param"
          },
          "configuration": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/$defs/param"
            }
          }
        }
      }
    },
    "assemblies": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "assembly_ref",
          "hierarchy"
        ],
        "properties": {
          "hierarchy": {
            "type": "array",
            "items": {
              "$ref": "#/$defs/node"
            }
          }
        }
      }
    },
    "materials": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "material_id",
          "official_name",
          "type",
          "parameters"
        ],
        "properties": {
          "parameters": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/$defs/param"
            }
          }
        }
      }
    },
    "coverage_matrix": {
      "type": "array",
      "minItems": 48,
      "maxItems": 48
    }
  }
}