{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Pine Assembly Workshop operating model v1",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "slug": {
      "type": "string"
    },
    "title": {
      "type": "string"
    },
    "industry": {
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "workflows": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "asOf": {
      "type": "string"
    },
    "source": {
      "type": "string"
    },
    "tables": {
      "type": "object",
      "properties": {
        "parts": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {}
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "part_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "description": {
                    "type": "string"
                  },
                  "unit_cost": {
                    "type": "number"
                  },
                  "opening": {
                    "type": "number"
                  },
                  "reorder_point": {
                    "type": "number"
                  }
                },
                "required": [
                  "part_id",
                  "description",
                  "unit_cost",
                  "opening",
                  "reorder_point"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "bom": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "column": {
                    "type": "string"
                  },
                  "table": {
                    "type": "string"
                  },
                  "targetColumn": {
                    "type": "string"
                  }
                },
                "required": [
                  "column",
                  "table",
                  "targetColumn"
                ],
                "additionalProperties": false
              }
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "bom_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "parent_id": {
                    "type": "string"
                  },
                  "component_id": {
                    "type": "string"
                  },
                  "quantity": {
                    "type": "number"
                  }
                },
                "required": [
                  "bom_id",
                  "parent_id",
                  "component_id",
                  "quantity"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "movements": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "column": {
                    "type": "string"
                  },
                  "table": {
                    "type": "string"
                  },
                  "targetColumn": {
                    "type": "string"
                  }
                },
                "required": [
                  "column",
                  "table",
                  "targetColumn"
                ],
                "additionalProperties": false
              }
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "movement_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "part_id": {
                    "type": "string"
                  },
                  "date": {
                    "type": "string"
                  },
                  "opening": {
                    "type": "number"
                  },
                  "received": {
                    "type": "number"
                  },
                  "issued": {
                    "type": "number"
                  },
                  "closing": {
                    "type": "number"
                  }
                },
                "required": [
                  "movement_id",
                  "part_id",
                  "date",
                  "opening",
                  "received",
                  "issued",
                  "closing"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "suppliers": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {}
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "supplier_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "name": {
                    "type": "string"
                  }
                },
                "required": [
                  "supplier_id",
                  "name"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "procurement": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "column": {
                    "type": "string"
                  },
                  "table": {
                    "type": "string"
                  },
                  "targetColumn": {
                    "type": "string"
                  }
                },
                "required": [
                  "column",
                  "table",
                  "targetColumn"
                ],
                "additionalProperties": false
              }
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "purchase_order_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "supplier_id": {
                    "type": "string"
                  },
                  "movement_id": {
                    "type": "string"
                  },
                  "part_id": {
                    "type": "string"
                  },
                  "quantity": {
                    "type": "number"
                  },
                  "unit_cost": {
                    "type": "number"
                  },
                  "amount": {
                    "type": "number"
                  }
                },
                "required": [
                  "purchase_order_id",
                  "supplier_id",
                  "movement_id",
                  "part_id",
                  "quantity",
                  "unit_cost",
                  "amount"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "production_orders": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "column": {
                    "type": "string"
                  },
                  "table": {
                    "type": "string"
                  },
                  "targetColumn": {
                    "type": "string"
                  }
                },
                "required": [
                  "column",
                  "table",
                  "targetColumn"
                ],
                "additionalProperties": false
              }
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "production_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "part_id": {
                    "type": "string"
                  },
                  "quantity": {
                    "type": "number"
                  },
                  "status": {
                    "type": "string"
                  },
                  "due_date": {
                    "type": "string"
                  }
                },
                "required": [
                  "production_id",
                  "part_id",
                  "quantity",
                  "status",
                  "due_date"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "material_requirements": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "column": {
                    "type": "string"
                  },
                  "table": {
                    "type": "string"
                  },
                  "targetColumn": {
                    "type": "string"
                  }
                },
                "required": [
                  "column",
                  "table",
                  "targetColumn"
                ],
                "additionalProperties": false
              }
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "requirement_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "production_id": {
                    "type": "string"
                  },
                  "part_id": {
                    "type": "string"
                  },
                  "quantity": {
                    "type": "number"
                  }
                },
                "required": [
                  "requirement_id",
                  "production_id",
                  "part_id",
                  "quantity"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "routes": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {}
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "route_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "name": {
                    "type": "string"
                  },
                  "planned_km": {
                    "type": "number"
                  },
                  "vehicle_capacity": {
                    "type": "number"
                  }
                },
                "required": [
                  "route_id",
                  "name",
                  "planned_km",
                  "vehicle_capacity"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "shipments": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "column": {
                    "type": "string"
                  },
                  "table": {
                    "type": "string"
                  },
                  "targetColumn": {
                    "type": "string"
                  }
                },
                "required": [
                  "column",
                  "table",
                  "targetColumn"
                ],
                "additionalProperties": false
              }
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "shipment_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "route_id": {
                    "type": "string"
                  },
                  "stop_number": {
                    "type": "number"
                  },
                  "parcels": {
                    "type": "number"
                  },
                  "status": {
                    "type": "string"
                  },
                  "delivered_parcels": {
                    "type": "number"
                  },
                  "planned_minutes": {
                    "type": "number"
                  },
                  "actual_minutes": {
                    "type": "number"
                  },
                  "part_id": {
                    "type": "string"
                  }
                },
                "required": [
                  "shipment_id",
                  "route_id",
                  "stop_number",
                  "parcels",
                  "status",
                  "delivered_parcels",
                  "planned_minutes",
                  "actual_minutes",
                  "part_id"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "vehicles": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "column": {
                    "type": "string"
                  },
                  "table": {
                    "type": "string"
                  },
                  "targetColumn": {
                    "type": "string"
                  }
                },
                "required": [
                  "column",
                  "table",
                  "targetColumn"
                ],
                "additionalProperties": false
              }
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "vehicle_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "route_id": {
                    "type": "string"
                  },
                  "capacity_parcels": {
                    "type": "number"
                  },
                  "fuel_litres": {
                    "type": "number"
                  }
                },
                "required": [
                  "vehicle_id",
                  "route_id",
                  "capacity_parcels",
                  "fuel_litres"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "shipment_exceptions": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "column": {
                    "type": "string"
                  },
                  "table": {
                    "type": "string"
                  },
                  "targetColumn": {
                    "type": "string"
                  }
                },
                "required": [
                  "column",
                  "table",
                  "targetColumn"
                ],
                "additionalProperties": false
              }
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "exception_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "shipment_id": {
                    "type": "string"
                  },
                  "reason": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string"
                  }
                },
                "required": [
                  "exception_id",
                  "shipment_id",
                  "reason",
                  "status"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "parts",
        "bom",
        "movements",
        "suppliers",
        "procurement",
        "production_orders",
        "material_requirements",
        "routes",
        "shipments",
        "vehicles",
        "shipment_exceptions"
      ],
      "additionalProperties": false
    },
    "metrics": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "value": {
            "type": "number"
          },
          "unit": {
            "type": "string"
          },
          "calculation": {
            "type": "string"
          },
          "formula": {
            "type": "object",
            "properties": {
              "op": {
                "type": "string"
              },
              "table": {
                "type": "string"
              },
              "column": {
                "type": "string"
              }
            },
            "required": [
              "op",
              "table"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "id",
          "label",
          "value",
          "unit",
          "calculation",
          "formula"
        ],
        "additionalProperties": false
      }
    },
    "chart": {
      "type": "object",
      "properties": {
        "title": {
          "type": "string"
        },
        "unit": {
          "type": "string"
        },
        "points": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "label": {
                "type": "string"
              },
              "value": {
                "type": "number"
              }
            },
            "required": [
              "label",
              "value"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "title",
        "unit",
        "points"
      ],
      "additionalProperties": false
    },
    "notes": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  },
  "required": [
    "id",
    "slug",
    "title",
    "industry",
    "description",
    "workflows",
    "asOf",
    "source",
    "tables",
    "metrics",
    "chart",
    "notes"
  ],
  "additionalProperties": false,
  "x-relationalRules": [
    {
      "table": "parts",
      "unique": "part_id",
      "foreignKeys": []
    },
    {
      "table": "bom",
      "unique": "bom_id",
      "foreignKeys": [
        {
          "column": "parent_id",
          "table": "parts",
          "targetColumn": "part_id"
        },
        {
          "column": "component_id",
          "table": "parts",
          "targetColumn": "part_id"
        }
      ]
    },
    {
      "table": "movements",
      "unique": "movement_id",
      "foreignKeys": [
        {
          "column": "part_id",
          "table": "parts",
          "targetColumn": "part_id"
        }
      ]
    },
    {
      "table": "suppliers",
      "unique": "supplier_id",
      "foreignKeys": []
    },
    {
      "table": "procurement",
      "unique": "purchase_order_id",
      "foreignKeys": [
        {
          "column": "supplier_id",
          "table": "suppliers",
          "targetColumn": "supplier_id"
        },
        {
          "column": "movement_id",
          "table": "movements",
          "targetColumn": "movement_id"
        },
        {
          "column": "part_id",
          "table": "parts",
          "targetColumn": "part_id"
        }
      ]
    },
    {
      "table": "production_orders",
      "unique": "production_id",
      "foreignKeys": [
        {
          "column": "part_id",
          "table": "parts",
          "targetColumn": "part_id"
        }
      ]
    },
    {
      "table": "material_requirements",
      "unique": "requirement_id",
      "foreignKeys": [
        {
          "column": "production_id",
          "table": "production_orders",
          "targetColumn": "production_id"
        },
        {
          "column": "part_id",
          "table": "parts",
          "targetColumn": "part_id"
        }
      ]
    },
    {
      "table": "routes",
      "unique": "route_id",
      "foreignKeys": []
    },
    {
      "table": "shipments",
      "unique": "shipment_id",
      "foreignKeys": [
        {
          "column": "route_id",
          "table": "routes",
          "targetColumn": "route_id"
        },
        {
          "column": "part_id",
          "table": "parts",
          "targetColumn": "part_id"
        }
      ]
    },
    {
      "table": "vehicles",
      "unique": "vehicle_id",
      "foreignKeys": [
        {
          "column": "route_id",
          "table": "routes",
          "targetColumn": "route_id"
        }
      ]
    },
    {
      "table": "shipment_exceptions",
      "unique": "exception_id",
      "foreignKeys": [
        {
          "column": "shipment_id",
          "table": "shipments",
          "targetColumn": "shipment_id"
        }
      ]
    }
  ]
}
