{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://catalog.lintel.tools/schemas/schemastore/abcinventorymoduledata/versions/1.0.0.json",
  "title": "ABCInventoryModuleData JSON Schema",
  "description": "Schema defining the structure of ABCInventoryModuleData including Principal Data, inventory, and transaction data in ABC-Plan's Inventory Management Module.",
  "x-lintel": {
    "source": "https://www.schemastore.org/abc-inventory-module-data-1.0.0.json",
    "sourceSha256": "c5e31d4dff8384276609547cc693e823c5f309064c732f4941e69a2d25ccddc0",
    "fileMatch": [
      "abc-inventory-module-data-*.json"
    ],
    "parsers": [
      "json"
    ]
  },
  "type": "object",
  "properties": {
    "$schema": {
      "description": "Link to <https://www.schemastore.org/abc-inventory-module-data-1.0.0.json>",
      "const": "https://www.schemastore.org/abc-inventory-module-data-1.0.0.json"
    },
    "ABCInventoryEntries": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
          "$ref": "#/$defs/ABCInventoryEntry"
        }
      }
    },
    "ABCLocations": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
          "type": "object",
          "required": [
            "name",
            "isActive"
          ],
          "properties": {
            "isActive": {
              "type": "boolean"
            },
            "name": {
              "type": "string"
            }
          },
          "additionalProperties": false
        }
      }
    },
    "ABCMaterialCategories": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
          "type": "object",
          "required": [
            "name",
            "isActive",
            "prefix"
          ],
          "properties": {
            "isActive": {
              "type": "boolean"
            },
            "name": {
              "type": "string"
            },
            "prefix": {
              "type": "string"
            }
          },
          "additionalProperties": false
        }
      }
    },
    "ABCMaterialNumbers": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
          "type": "object",
          "required": [
            "productID",
            "vendorID",
            "materialCategoryID",
            "number",
            "name",
            "description",
            "unitOfMeasure",
            "isActive"
          ],
          "properties": {
            "description": {
              "type": "string"
            },
            "isActive": {
              "type": "boolean"
            },
            "materialCategoryID": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "number": {
              "type": "number"
            },
            "productID": {
              "type": [
                "string",
                "null"
              ]
            },
            "unitOfMeasure": {
              "type": "string"
            },
            "vendorID": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          "additionalProperties": false
        }
      }
    },
    "ABCProducts": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
          "type": "object",
          "required": [
            "name",
            "isActive"
          ],
          "properties": {
            "isActive": {
              "type": "boolean"
            },
            "name": {
              "type": "string"
            }
          },
          "additionalProperties": false
        }
      }
    },
    "ABCReasonCodes": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
          "type": "object",
          "required": [
            "code",
            "description",
            "isActive"
          ],
          "properties": {
            "description": {
              "type": "string"
            },
            "code": {
              "type": "string"
            },
            "isActive": {
              "type": "boolean"
            }
          },
          "additionalProperties": false
        }
      }
    },
    "ABCTransactions": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/ABCInventoryTransaction"
      }
    },
    "ABCVendors": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
          "type": "object",
          "required": [
            "name",
            "isActive"
          ],
          "properties": {
            "isActive": {
              "type": "boolean"
            },
            "name": {
              "type": "string"
            }
          },
          "additionalProperties": false
        }
      }
    }
  },
  "required": [
    "$schema",
    "ABCProducts",
    "ABCVendors",
    "ABCMaterialCategories",
    "ABCMaterialNumbers",
    "ABCLocations",
    "ABCReasonCodes",
    "ABCTransactions",
    "ABCInventoryEntries"
  ],
  "additionalProperties": false,
  "$defs": {
    "ABCInventoryAdjustTransaction": {
      "type": "object",
      "required": [
        "uid",
        "timestamp",
        "transactionType",
        "transactionData"
      ],
      "properties": {
        "timestamp": {
          "type": "number"
        },
        "transactionData": {
          "type": "object",
          "required": [
            "lotID",
            "newQuantity",
            "reasonCodeID",
            "lotNumber",
            "materialNumberID",
            "locationID",
            "productID",
            "notes"
          ],
          "properties": {
            "locationID": {
              "type": "string"
            },
            "lotID": {
              "type": "string"
            },
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "newQuantity": {
              "type": "number"
            },
            "notes": {
              "type": "string"
            },
            "productID": {
              "type": [
                "string",
                "null"
              ]
            },
            "reasonCodeID": {
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        "transactionType": {
          "const": "adjust"
        },
        "uid": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "ABCInventoryBuildTransaction": {
      "type": "object",
      "required": [
        "uid",
        "timestamp",
        "transactionType",
        "transactionData",
        "targetLotID"
      ],
      "properties": {
        "targetLotID": {
          "type": "string"
        },
        "timestamp": {
          "type": "number"
        },
        "transactionData": {
          "type": "object",
          "required": [
            "lotNumber",
            "materialNumberID",
            "quantity",
            "dateOfExpiry",
            "dateOfManufacture",
            "poNumber",
            "statusID",
            "locationID",
            "cost",
            "upstreams",
            "upstreamIDs",
            "upstreamLotNumbers",
            "upstreamQuantities",
            "upstreamMaterialNumberIDs",
            "upstreamLocationIDs",
            "productID",
            "upstreamProductIDs",
            "notes"
          ],
          "properties": {
            "cost": {
              "type": "number"
            },
            "dateOfExpiry": {
              "type": "string",
              "format": "date"
            },
            "dateOfManufacture": {
              "type": "string",
              "format": "date"
            },
            "locationID": {
              "type": "string"
            },
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "notes": {
              "type": "string"
            },
            "poNumber": {
              "type": "string"
            },
            "productID": {
              "type": [
                "string",
                "null"
              ]
            },
            "quantity": {
              "type": "number"
            },
            "statusID": {
              "$ref": "#/$defs/ABCStatus"
            },
            "upstreamIDs": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "upstreamLocationIDs": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "upstreamLotNumbers": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "upstreamMaterialNumberIDs": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "upstreamProductIDs": {
              "type": "array",
              "items": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "upstreamQuantities": {
              "type": "array",
              "items": {
                "type": "number"
              }
            },
            "upstreams": {
              "type": "array",
              "items": {
                "type": "object",
                "required": [
                  "lotID",
                  "quantity"
                ],
                "properties": {
                  "lotID": {
                    "type": "string"
                  },
                  "quantity": {
                    "type": "number"
                  }
                },
                "additionalProperties": false
              }
            }
          },
          "additionalProperties": false
        },
        "transactionType": {
          "const": "build"
        },
        "uid": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "ABCInventoryChangeExpiryTransaction": {
      "type": "object",
      "required": [
        "uid",
        "timestamp",
        "transactionType",
        "transactionData"
      ],
      "properties": {
        "timestamp": {
          "type": "number"
        },
        "transactionData": {
          "type": "object",
          "required": [
            "lotID",
            "newDateOfExpiry",
            "lotNumber",
            "materialNumberID",
            "locationID",
            "productID",
            "notes"
          ],
          "properties": {
            "locationID": {
              "type": "string"
            },
            "lotID": {
              "type": "string"
            },
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "newDateOfExpiry": {
              "type": "string"
            },
            "notes": {
              "type": "string"
            },
            "productID": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          "additionalProperties": false
        },
        "transactionType": {
          "const": "changeExpiry"
        },
        "uid": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "ABCInventoryDestroyTransaction": {
      "type": "object",
      "required": [
        "uid",
        "timestamp",
        "transactionType",
        "transactionData"
      ],
      "properties": {
        "timestamp": {
          "type": "number"
        },
        "transactionData": {
          "type": "object",
          "required": [
            "lotID",
            "lotNumber",
            "materialNumberID",
            "locationID",
            "productID",
            "notes"
          ],
          "properties": {
            "locationID": {
              "type": "string"
            },
            "lotID": {
              "type": "string"
            },
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "notes": {
              "type": "string"
            },
            "productID": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          "additionalProperties": false
        },
        "transactionType": {
          "const": "destroy"
        },
        "uid": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "ABCInventoryDistributeTransaction": {
      "type": "object",
      "required": [
        "uid",
        "timestamp",
        "transactionType",
        "transactionData"
      ],
      "properties": {
        "timestamp": {
          "type": "number"
        },
        "transactionData": {
          "type": "object",
          "required": [
            "lotID",
            "quantity",
            "lotNumber",
            "materialNumberID",
            "locationID",
            "productID",
            "notes"
          ],
          "properties": {
            "locationID": {
              "type": "string"
            },
            "lotID": {
              "type": "string"
            },
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "notes": {
              "type": "string"
            },
            "productID": {
              "type": [
                "string",
                "null"
              ]
            },
            "quantity": {
              "type": "number"
            }
          },
          "additionalProperties": false
        },
        "transactionType": {
          "const": "distribute"
        },
        "uid": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "ABCInventoryEntry": {
      "oneOf": [
        {
          "$ref": "#/$defs/ABCInventoryEntryWithoutUpstreams"
        },
        {
          "$ref": "#/$defs/ABCInventoryEntryWithUpstreams"
        }
      ]
    },
    "ABCInventoryEntryWithUpstreams": {
      "type": "object",
      "required": [
        "lotNumber",
        "materialNumberID",
        "productID",
        "quantity",
        "dateOfExpiry",
        "dateOfManufacture",
        "poNumber",
        "statusID",
        "locationID",
        "cost",
        "hasUpstreams",
        "upstreamIDs",
        "upstreamQuantities",
        "upstreamLotNumbers",
        "transactionNotes",
        "lotNumberLowercase"
      ],
      "properties": {
        "cost": {
          "type": "number"
        },
        "dateOfExpiry": {
          "type": "string",
          "format": "date"
        },
        "dateOfManufacture": {
          "type": "string",
          "format": "date"
        },
        "hasUpstreams": {
          "const": true
        },
        "locationID": {
          "type": "string"
        },
        "lotNumber": {
          "type": "string"
        },
        "lotNumberLowercase": {
          "type": "string"
        },
        "materialNumberID": {
          "type": "string"
        },
        "poNumber": {
          "type": "string"
        },
        "productID": {
          "type": [
            "string",
            "null"
          ]
        },
        "quantity": {
          "type": "number"
        },
        "statusID": {
          "$ref": "#/$defs/ABCStatus"
        },
        "transactionNotes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "upstreamIDs": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "upstreamLotNumbers": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "upstreamQuantities": {
          "type": "array",
          "items": {
            "type": "number"
          }
        }
      },
      "additionalProperties": false
    },
    "ABCInventoryEntryWithoutUpstreams": {
      "type": "object",
      "required": [
        "lotNumber",
        "materialNumberID",
        "productID",
        "quantity",
        "dateOfExpiry",
        "dateOfManufacture",
        "poNumber",
        "statusID",
        "locationID",
        "cost",
        "hasUpstreams",
        "transactionNotes",
        "lotNumberLowercase"
      ],
      "properties": {
        "cost": {
          "type": "number"
        },
        "dateOfExpiry": {
          "type": "string",
          "format": "date"
        },
        "dateOfManufacture": {
          "type": "string",
          "format": "date"
        },
        "hasUpstreams": {
          "const": false
        },
        "locationID": {
          "type": "string"
        },
        "lotNumber": {
          "type": "string"
        },
        "lotNumberLowercase": {
          "type": "string"
        },
        "materialNumberID": {
          "type": "string"
        },
        "poNumber": {
          "type": "string"
        },
        "productID": {
          "type": [
            "string",
            "null"
          ]
        },
        "quantity": {
          "type": "number"
        },
        "statusID": {
          "$ref": "#/$defs/ABCStatus"
        },
        "transactionNotes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false
    },
    "ABCInventoryReceiveTransaction": {
      "type": "object",
      "required": [
        "uid",
        "timestamp",
        "transactionType",
        "transactionData",
        "targetLotID"
      ],
      "properties": {
        "targetLotID": {
          "type": "string"
        },
        "timestamp": {
          "type": "number"
        },
        "transactionData": {
          "type": "object",
          "required": [
            "lotNumber",
            "materialNumberID",
            "quantity",
            "dateOfExpiry",
            "dateOfManufacture",
            "poNumber",
            "statusID",
            "locationID",
            "cost",
            "productID",
            "notes"
          ],
          "properties": {
            "cost": {
              "type": "number"
            },
            "dateOfExpiry": {
              "type": "string",
              "format": "date"
            },
            "dateOfManufacture": {
              "type": "string",
              "format": "date"
            },
            "locationID": {
              "type": "string"
            },
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "notes": {
              "type": "string"
            },
            "poNumber": {
              "type": "string"
            },
            "productID": {
              "type": [
                "string",
                "null"
              ]
            },
            "quantity": {
              "type": "number"
            },
            "statusID": {
              "$ref": "#/$defs/ABCStatus"
            }
          },
          "additionalProperties": false
        },
        "transactionType": {
          "const": "receive"
        },
        "uid": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "ABCInventorySellTransaction": {
      "type": "object",
      "required": [
        "uid",
        "timestamp",
        "transactionType",
        "transactionData"
      ],
      "properties": {
        "timestamp": {
          "type": "number"
        },
        "transactionData": {
          "type": "object",
          "required": [
            "lotID",
            "quantity",
            "cost",
            "lotNumber",
            "materialNumberID",
            "locationID",
            "productID",
            "notes"
          ],
          "properties": {
            "cost": {
              "type": "number"
            },
            "locationID": {
              "type": "string"
            },
            "lotID": {
              "type": "string"
            },
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "notes": {
              "type": "string"
            },
            "productID": {
              "type": [
                "string",
                "null"
              ]
            },
            "quantity": {
              "type": "number"
            }
          },
          "additionalProperties": false
        },
        "transactionType": {
          "const": "sell"
        },
        "uid": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "ABCInventoryStatusChangeTransaction": {
      "type": "object",
      "required": [
        "uid",
        "timestamp",
        "transactionType",
        "transactionData",
        "targetLotID"
      ],
      "properties": {
        "targetLotID": {
          "type": "string"
        },
        "timestamp": {
          "type": "number"
        },
        "transactionData": {
          "type": "object",
          "required": [
            "lotID",
            "newStatusID",
            "quantity",
            "lotNumber",
            "materialNumberID",
            "locationID",
            "productID",
            "notes"
          ],
          "properties": {
            "locationID": {
              "type": "string"
            },
            "lotID": {
              "type": "string"
            },
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "newStatusID": {
              "$ref": "#/$defs/ABCStatus"
            },
            "notes": {
              "type": "string"
            },
            "productID": {
              "type": [
                "string",
                "null"
              ]
            },
            "quantity": {
              "type": "number"
            }
          },
          "additionalProperties": false
        },
        "transactionType": {
          "const": "statusChange"
        },
        "uid": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "ABCInventoryTransaction": {
      "oneOf": [
        {
          "$ref": "#/$defs/ABCInventoryReceiveTransaction"
        },
        {
          "$ref": "#/$defs/ABCInventoryBuildTransaction"
        },
        {
          "$ref": "#/$defs/ABCInventoryTransferTransaction"
        },
        {
          "$ref": "#/$defs/ABCInventoryStatusChangeTransaction"
        },
        {
          "$ref": "#/$defs/ABCInventoryDistributeTransaction"
        },
        {
          "$ref": "#/$defs/ABCInventoryDestroyTransaction"
        },
        {
          "$ref": "#/$defs/ABCInventorySellTransaction"
        },
        {
          "$ref": "#/$defs/ABCInventoryAdjustTransaction"
        },
        {
          "$ref": "#/$defs/ABCInventoryChangeExpiryTransaction"
        }
      ]
    },
    "ABCInventoryTransferTransaction": {
      "type": "object",
      "required": [
        "uid",
        "timestamp",
        "transactionType",
        "transactionData",
        "targetLotID"
      ],
      "properties": {
        "targetLotID": {
          "type": "string"
        },
        "timestamp": {
          "type": "number"
        },
        "transactionData": {
          "type": "object",
          "required": [
            "lotID",
            "newLocationID",
            "quantity",
            "lotNumber",
            "materialNumberID",
            "locationID",
            "productID",
            "notes"
          ],
          "properties": {
            "locationID": {
              "type": "string"
            },
            "lotID": {
              "type": "string"
            },
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "newLocationID": {
              "type": "string"
            },
            "notes": {
              "type": "string"
            },
            "productID": {
              "type": [
                "string",
                "null"
              ]
            },
            "quantity": {
              "type": "number"
            }
          },
          "additionalProperties": false
        },
        "transactionType": {
          "const": "transfer"
        },
        "uid": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "ABCStatus": {
      "enum": [
        "RELEASED",
        "CONDITIONAL_RELEASED",
        "QUARANTINE",
        "ON_HOLD",
        "EXPIRED",
        "DAMAGED"
      ]
    }
  }
}
