{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://json.schemastore.org/abc-inventory-module-data-5.2.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. Version 5.2.0 adds Rejected status.",
  "type": "object",
  "definitions": {
    "ABCStatus": {
      "type": "string",
      "enum": [
        "RELEASED",
        "CONDITIONAL_RELEASED",
        "QUARANTINE",
        "IN_TRANSIT",
        "ON_HOLD",
        "EXPIRED",
        "DAMAGED",
        "REJECTED"
      ]
    },
    "ABCInventoryReceiveTransaction": {
      "type": "object",
      "properties": {
        "uid": {
          "type": "string"
        },
        "timestamp": {
          "type": "number"
        },
        "transactionType": {
          "type": "string",
          "enum": ["receive"]
        },
        "transactionData": {
          "type": "object",
          "properties": {
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "materialCategoryID": {
              "type": "string"
            },
            "quantity": {
              "type": "number"
            },
            "dateOfExpiry": {
              "type": "string",
              "format": "date"
            },
            "dateOfManufacture": {
              "type": "string",
              "format": "date"
            },
            "poNumber": {
              "type": "string"
            },
            "statusID": {
              "$ref": "#/definitions/ABCStatus"
            },
            "locationID": {
              "type": "string"
            },
            "tagIDs": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "productID": {
              "type": ["string", "null"]
            },
            "notes": {
              "type": "string"
            }
          },
          "required": [
            "lotNumber",
            "materialNumberID",
            "materialCategoryID",
            "quantity",
            "dateOfExpiry",
            "dateOfManufacture",
            "poNumber",
            "statusID",
            "locationID",
            "tagIDs",
            "productID",
            "notes"
          ],
          "additionalProperties": false
        },
        "targetLotID": {
          "type": "string"
        }
      },
      "required": ["uid", "timestamp", "transactionType", "transactionData"],
      "additionalProperties": false
    },
    "ABCInventoryBuildTransaction": {
      "type": "object",
      "properties": {
        "uid": {
          "type": "string"
        },
        "timestamp": {
          "type": "number"
        },
        "transactionType": {
          "type": "string",
          "enum": ["build"]
        },
        "transactionData": {
          "type": "object",
          "properties": {
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "materialCategoryID": {
              "type": "string"
            },
            "quantity": {
              "type": "number"
            },
            "dateOfExpiry": {
              "type": "string",
              "format": "date"
            },
            "dateOfManufacture": {
              "type": "string",
              "format": "date"
            },
            "poNumber": {
              "type": "string"
            },
            "statusID": {
              "$ref": "#/definitions/ABCStatus"
            },
            "locationID": {
              "type": "string"
            },
            "tagIDs": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "upstreams": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "lotID": {
                    "type": "string"
                  },
                  "quantity": {
                    "type": "number"
                  }
                },
                "required": ["lotID", "quantity"],
                "additionalProperties": false
              }
            },
            "upstreamIDs": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "upstreamLotNumbers": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "upstreamQuantities": {
              "type": "array",
              "items": {
                "type": "number"
              }
            },
            "upstreamMaterialNumberIDs": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "upstreamMaterialCategoryIDs": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "upstreamLocationIDs": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "productID": {
              "type": ["string", "null"]
            },
            "upstreamProductIDs": {
              "type": "array",
              "items": {
                "type": ["string", "null"]
              }
            },
            "notes": {
              "type": "string"
            }
          },
          "required": [
            "lotNumber",
            "materialNumberID",
            "materialCategoryID",
            "quantity",
            "dateOfExpiry",
            "dateOfManufacture",
            "poNumber",
            "statusID",
            "locationID",
            "tagIDs",
            "upstreams",
            "upstreamIDs",
            "upstreamLotNumbers",
            "upstreamQuantities",
            "upstreamMaterialNumberIDs",
            "upstreamMaterialCategoryIDs",
            "upstreamLocationIDs",
            "productID",
            "upstreamProductIDs",
            "notes"
          ],
          "additionalProperties": false
        },
        "targetLotID": {
          "type": "string"
        }
      },
      "required": ["uid", "timestamp", "transactionType", "transactionData"],
      "additionalProperties": false
    },
    "ABCInventoryTransferTransaction": {
      "type": "object",
      "properties": {
        "uid": {
          "type": "string"
        },
        "timestamp": {
          "type": "number"
        },
        "transactionType": {
          "type": "string",
          "enum": ["transfer"]
        },
        "transactionData": {
          "type": "object",
          "properties": {
            "lotID": {
              "type": "string"
            },
            "newLocationID": {
              "type": "string"
            },
            "quantity": {
              "type": "number"
            },
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "locationID": {
              "type": "string"
            },
            "productID": {
              "type": ["string", "null"]
            },
            "materialCategoryID": {
              "type": "string"
            },
            "notes": {
              "type": "string"
            }
          },
          "required": [
            "lotID",
            "newLocationID",
            "quantity",
            "lotNumber",
            "materialNumberID",
            "locationID",
            "productID",
            "materialCategoryID",
            "notes"
          ],
          "additionalProperties": false
        },
        "targetLotID": {
          "type": "string"
        }
      },
      "required": ["uid", "timestamp", "transactionType", "transactionData"],
      "additionalProperties": false
    },
    "ABCInventoryStatusChangeTransaction": {
      "type": "object",
      "properties": {
        "uid": {
          "type": "string"
        },
        "timestamp": {
          "type": "number"
        },
        "transactionType": {
          "type": "string",
          "enum": ["statusChange"]
        },
        "transactionData": {
          "type": "object",
          "properties": {
            "lotID": {
              "type": "string"
            },
            "newStatusID": {
              "$ref": "#/definitions/ABCStatus"
            },
            "quantity": {
              "type": "number"
            },
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "locationID": {
              "type": "string"
            },
            "productID": {
              "type": ["string", "null"]
            },
            "materialCategoryID": {
              "type": "string"
            },
            "notes": {
              "type": "string"
            }
          },
          "required": [
            "lotID",
            "newStatusID",
            "quantity",
            "lotNumber",
            "materialNumberID",
            "locationID",
            "productID",
            "materialCategoryID",
            "notes"
          ],
          "additionalProperties": false
        },
        "targetLotID": {
          "type": "string"
        }
      },
      "required": ["uid", "timestamp", "transactionType", "transactionData"],
      "additionalProperties": false
    },
    "ABCInventoryDistributeTransaction": {
      "type": "object",
      "properties": {
        "uid": {
          "type": "string"
        },
        "timestamp": {
          "type": "number"
        },
        "transactionType": {
          "type": "string",
          "enum": ["distribute"]
        },
        "transactionData": {
          "type": "object",
          "properties": {
            "lotID": {
              "type": "string"
            },
            "quantity": {
              "type": "number"
            },
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "locationID": {
              "type": "string"
            },
            "productID": {
              "type": ["string", "null"]
            },
            "materialCategoryID": {
              "type": "string"
            },
            "notes": {
              "type": "string"
            }
          },
          "required": [
            "lotID",
            "quantity",
            "lotNumber",
            "materialNumberID",
            "locationID",
            "productID",
            "materialCategoryID",
            "notes"
          ],
          "additionalProperties": false
        }
      },
      "required": ["uid", "timestamp", "transactionType", "transactionData"],
      "additionalProperties": false
    },
    "ABCInventoryDestroyTransaction": {
      "type": "object",
      "properties": {
        "uid": {
          "type": "string"
        },
        "timestamp": {
          "type": "number"
        },
        "transactionType": {
          "type": "string",
          "enum": ["destroy"]
        },
        "transactionData": {
          "type": "object",
          "properties": {
            "lotID": {
              "type": "string"
            },
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "locationID": {
              "type": "string"
            },
            "productID": {
              "type": ["string", "null"]
            },
            "materialCategoryID": {
              "type": "string"
            },
            "notes": {
              "type": "string"
            }
          },
          "required": [
            "lotID",
            "lotNumber",
            "materialNumberID",
            "locationID",
            "productID",
            "materialCategoryID",
            "notes"
          ],
          "additionalProperties": false
        }
      },
      "required": ["uid", "timestamp", "transactionType", "transactionData"],
      "additionalProperties": false
    },
    "ABCInventorySellTransaction": {
      "type": "object",
      "properties": {
        "uid": {
          "type": "string"
        },
        "timestamp": {
          "type": "number"
        },
        "transactionType": {
          "type": "string",
          "enum": ["sell"]
        },
        "transactionData": {
          "type": "object",
          "properties": {
            "lotID": {
              "type": "string"
            },
            "quantity": {
              "type": "number"
            },
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "locationID": {
              "type": "string"
            },
            "productID": {
              "type": ["string", "null"]
            },
            "materialCategoryID": {
              "type": "string"
            },
            "notes": {
              "type": "string"
            }
          },
          "required": [
            "lotID",
            "quantity",
            "lotNumber",
            "materialNumberID",
            "locationID",
            "productID",
            "materialCategoryID",
            "notes"
          ],
          "additionalProperties": false
        }
      },
      "required": ["uid", "timestamp", "transactionType", "transactionData"],
      "additionalProperties": false
    },
    "ABCInventoryAdjustTransaction": {
      "type": "object",
      "properties": {
        "uid": {
          "type": "string"
        },
        "timestamp": {
          "type": "number"
        },
        "transactionType": {
          "type": "string",
          "enum": ["adjust"]
        },
        "transactionData": {
          "type": "object",
          "properties": {
            "lotID": {
              "type": "string"
            },
            "newQuantity": {
              "type": "number"
            },
            "reasonCodeID": {
              "type": "string"
            },
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "locationID": {
              "type": "string"
            },
            "productID": {
              "type": ["string", "null"]
            },
            "materialCategoryID": {
              "type": "string"
            },
            "notes": {
              "type": "string"
            }
          },
          "required": [
            "lotID",
            "newQuantity",
            "reasonCodeID",
            "lotNumber",
            "materialNumberID",
            "locationID",
            "productID",
            "materialCategoryID",
            "notes"
          ],
          "additionalProperties": false
        },
        "oldQuantity": {
          "type": "number"
        }
      },
      "required": [
        "uid",
        "timestamp",
        "transactionType",
        "transactionData",
        "oldQuantity"
      ],
      "additionalProperties": false
    },
    "ABCInventoryChangeExpiryTransaction": {
      "type": "object",
      "properties": {
        "uid": {
          "type": "string"
        },
        "timestamp": {
          "type": "number"
        },
        "transactionType": {
          "type": "string",
          "enum": ["changeExpiry"]
        },
        "transactionData": {
          "type": "object",
          "properties": {
            "lotID": {
              "type": "string"
            },
            "newDateOfExpiry": {
              "type": "string"
            },
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "locationID": {
              "type": "string"
            },
            "productID": {
              "type": ["string", "null"]
            },
            "materialCategoryID": {
              "type": "string"
            },
            "notes": {
              "type": "string"
            }
          },
          "required": [
            "lotID",
            "newDateOfExpiry",
            "lotNumber",
            "materialNumberID",
            "locationID",
            "productID",
            "materialCategoryID",
            "notes"
          ],
          "additionalProperties": false
        }
      },
      "required": ["uid", "timestamp", "transactionType", "transactionData"],
      "additionalProperties": false
    },
    "ABCInventoryChangeAttributesTransaction": {
      "type": "object",
      "properties": {
        "uid": {
          "type": "string"
        },
        "timestamp": {
          "type": "number"
        },
        "transactionType": {
          "type": "string",
          "enum": ["changeAttributes"]
        },
        "transactionData": {
          "type": "object",
          "properties": {
            "lotID": {
              "type": "string"
            },
            "lotNumber": {
              "type": "string"
            },
            "materialNumberID": {
              "type": "string"
            },
            "materialCategoryID": {
              "type": "string"
            },
            "productID": {
              "type": ["string", "null"]
            },
            "locationID": {
              "type": "string"
            },
            "dateOfManufacture": {
              "type": "string",
              "format": "date"
            },
            "poNumber": {
              "type": "string"
            },
            "tagIDs": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "notes": {
              "type": "string"
            }
          },
          "required": [
            "lotID",
            "lotNumber",
            "materialNumberID",
            "materialCategoryID",
            "productID",
            "locationID"
          ],
          "additionalProperties": false
        }
      },
      "required": ["uid", "timestamp", "transactionType", "transactionData"],
      "additionalProperties": false
    },
    "ABCInventoryTransaction": {
      "oneOf": [
        { "$ref": "#/definitions/ABCInventoryReceiveTransaction" },
        { "$ref": "#/definitions/ABCInventoryBuildTransaction" },
        { "$ref": "#/definitions/ABCInventoryTransferTransaction" },
        { "$ref": "#/definitions/ABCInventoryStatusChangeTransaction" },
        { "$ref": "#/definitions/ABCInventoryDistributeTransaction" },
        { "$ref": "#/definitions/ABCInventoryDestroyTransaction" },
        { "$ref": "#/definitions/ABCInventorySellTransaction" },
        { "$ref": "#/definitions/ABCInventoryAdjustTransaction" },
        { "$ref": "#/definitions/ABCInventoryChangeExpiryTransaction" },
        { "$ref": "#/definitions/ABCInventoryChangeAttributesTransaction" }
      ]
    },
    "ABCInventoryEntryWithoutUpstreams": {
      "type": "object",
      "properties": {
        "lotNumber": {
          "type": "string"
        },
        "materialNumberID": {
          "type": "string"
        },
        "materialCategoryID": {
          "type": "string"
        },
        "productID": {
          "type": ["string", "null"]
        },
        "quantity": {
          "type": "number"
        },
        "dateOfExpiry": {
          "type": "string",
          "format": "date"
        },
        "dateOfManufacture": {
          "type": "string",
          "format": "date"
        },
        "poNumber": {
          "type": "string"
        },
        "statusID": {
          "$ref": "#/definitions/ABCStatus"
        },
        "locationID": {
          "type": "string"
        },
        "tagIDs": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "hasUpstreams": {
          "type": "boolean",
          "enum": [false]
        },
        "transactionNotes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "lotNumberLowercase": {
          "type": "string"
        }
      },
      "required": [
        "lotNumber",
        "materialNumberID",
        "materialCategoryID",
        "productID",
        "quantity",
        "dateOfExpiry",
        "dateOfManufacture",
        "poNumber",
        "statusID",
        "locationID",
        "tagIDs",
        "hasUpstreams",
        "transactionNotes",
        "lotNumberLowercase"
      ],
      "additionalProperties": false
    },
    "ABCInventoryEntryWithUpstreams": {
      "type": "object",
      "properties": {
        "lotNumber": {
          "type": "string"
        },
        "materialNumberID": {
          "type": "string"
        },
        "materialCategoryID": {
          "type": "string"
        },
        "productID": {
          "type": ["string", "null"]
        },
        "quantity": {
          "type": "number"
        },
        "dateOfExpiry": {
          "type": "string",
          "format": "date"
        },
        "dateOfManufacture": {
          "type": "string",
          "format": "date"
        },
        "poNumber": {
          "type": "string"
        },
        "statusID": {
          "$ref": "#/definitions/ABCStatus"
        },
        "locationID": {
          "type": "string"
        },
        "tagIDs": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "hasUpstreams": {
          "type": "boolean",
          "enum": [true]
        },
        "upstreamIDs": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "upstreamQuantities": {
          "type": "array",
          "items": {
            "type": "number"
          }
        },
        "upstreamLotNumbers": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "transactionNotes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "lotNumberLowercase": {
          "type": "string"
        }
      },
      "required": [
        "lotNumber",
        "materialNumberID",
        "materialCategoryID",
        "productID",
        "quantity",
        "dateOfExpiry",
        "dateOfManufacture",
        "poNumber",
        "statusID",
        "locationID",
        "tagIDs",
        "hasUpstreams",
        "upstreamIDs",
        "upstreamQuantities",
        "upstreamLotNumbers",
        "transactionNotes",
        "lotNumberLowercase"
      ],
      "additionalProperties": false
    },
    "ABCInventoryEntry": {
      "oneOf": [
        { "$ref": "#/definitions/ABCInventoryEntryWithoutUpstreams" },
        { "$ref": "#/definitions/ABCInventoryEntryWithUpstreams" }
      ]
    }
  },
  "properties": {
    "$schema": {
      "description": "Link to https://json.schemastore.org/abc-inventory-module-data-5.2.0.json",
      "type": "string",
      "enum": [
        "https://json.schemastore.org/abc-inventory-module-data-5.2.0.json"
      ]
    },
    "ABCProducts": {
      "type": "object",
      "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string"
            },
            "isActive": {
              "type": "boolean"
            }
          },
          "required": ["name", "isActive"],
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "ABCVendors": {
      "type": "object",
      "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string"
            },
            "isActive": {
              "type": "boolean"
            }
          },
          "required": ["name", "isActive"],
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "ABCMaterialCategories": {
      "type": "object",
      "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string"
            },
            "prefix": {
              "type": "string"
            },
            "isActive": {
              "type": "boolean"
            }
          },
          "required": ["name", "isActive", "prefix"],
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "ABCMaterialNumbers": {
      "type": "object",
      "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
          "type": "object",
          "properties": {
            "productID": {
              "type": ["string", "null"]
            },
            "vendorID": {
              "type": ["string", "null"]
            },
            "materialCategoryID": {
              "type": "string"
            },
            "number": {
              "type": "number"
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "unitOfMeasure": {
              "type": "string"
            },
            "isActive": {
              "type": "boolean"
            }
          },
          "required": [
            "productID",
            "vendorID",
            "materialCategoryID",
            "number",
            "name",
            "description",
            "unitOfMeasure",
            "isActive"
          ],
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "ABCLocations": {
      "type": "object",
      "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string"
            },
            "isActive": {
              "type": "boolean"
            }
          },
          "required": ["name", "isActive"],
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "ABCTags": {
      "type": "object",
      "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string"
            },
            "isActive": {
              "type": "boolean"
            }
          },
          "required": ["name", "isActive"],
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "ABCReasonCodes": {
      "type": "object",
      "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
          "type": "object",
          "properties": {
            "code": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "isActive": {
              "type": "boolean"
            }
          },
          "required": ["code", "description", "isActive"],
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "ABCTransactions": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/ABCInventoryTransaction"
      }
    },
    "ABCInventoryEntries": {
      "type": "object",
      "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
          "$ref": "#/definitions/ABCInventoryEntry"
        }
      },
      "additionalProperties": false
    }
  },
  "required": [
    "$schema",
    "ABCProducts",
    "ABCVendors",
    "ABCMaterialCategories",
    "ABCMaterialNumbers",
    "ABCLocations",
    "ABCTags",
    "ABCReasonCodes",
    "ABCTransactions",
    "ABCInventoryEntries"
  ],
  "additionalProperties": false
}
