{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Alder Books Reconciliation 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": {
        "bank": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {}
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "transaction_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "date": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  },
                  "opening_balance": {
                    "type": "number"
                  },
                  "amount": {
                    "type": "number"
                  },
                  "closing_balance": {
                    "type": "number"
                  },
                  "currency": {
                    "type": "string"
                  }
                },
                "required": [
                  "transaction_id",
                  "date",
                  "description",
                  "opening_balance",
                  "amount",
                  "closing_balance",
                  "currency"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "journal": {
          "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": {
                  "entry_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "transaction_id": {
                    "type": "string"
                  },
                  "account": {
                    "type": "string"
                  },
                  "debit": {
                    "type": "number"
                  },
                  "credit": {
                    "type": "number"
                  }
                },
                "required": [
                  "entry_id",
                  "transaction_id",
                  "account",
                  "debit",
                  "credit"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "accounts": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {}
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "account_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "name": {
                    "type": "string"
                  },
                  "type": {
                    "type": "string"
                  }
                },
                "required": [
                  "account_id",
                  "name",
                  "type"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "expenses": {
          "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": {
                  "expense_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "transaction_id": {
                    "type": "string"
                  },
                  "date": {
                    "type": "string"
                  },
                  "category": {
                    "type": "string"
                  },
                  "amount": {
                    "type": "number"
                  },
                  "currency": {
                    "type": "string"
                  }
                },
                "required": [
                  "expense_id",
                  "transaction_id",
                  "date",
                  "category",
                  "amount",
                  "currency"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "budgets": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {}
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "budget_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "month": {
                    "type": "string"
                  },
                  "category": {
                    "type": "string"
                  },
                  "budget": {
                    "type": "number"
                  },
                  "actual": {
                    "type": "number"
                  },
                  "remaining": {
                    "type": "number"
                  },
                  "currency": {
                    "type": "string"
                  }
                },
                "required": [
                  "budget_id",
                  "month",
                  "category",
                  "budget",
                  "actual",
                  "remaining",
                  "currency"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "receivables": {
          "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": {
                  "receivable_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "transaction_id": {
                    "type": "string"
                  },
                  "customer": {
                    "type": "string"
                  },
                  "invoice_amount": {
                    "type": "number"
                  },
                  "received": {
                    "type": "number"
                  },
                  "outstanding": {
                    "type": "number"
                  },
                  "currency": {
                    "type": "string"
                  }
                },
                "required": [
                  "receivable_id",
                  "transaction_id",
                  "customer",
                  "invoice_amount",
                  "received",
                  "outstanding",
                  "currency"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "bank",
        "journal",
        "accounts",
        "expenses",
        "budgets",
        "receivables"
      ],
      "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",
              "column"
            ],
            "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": "bank",
      "unique": "transaction_id",
      "foreignKeys": []
    },
    {
      "table": "journal",
      "unique": "entry_id",
      "foreignKeys": [
        {
          "column": "transaction_id",
          "table": "bank",
          "targetColumn": "transaction_id"
        }
      ]
    },
    {
      "table": "accounts",
      "unique": "account_id",
      "foreignKeys": []
    },
    {
      "table": "expenses",
      "unique": "expense_id",
      "foreignKeys": [
        {
          "column": "transaction_id",
          "table": "bank",
          "targetColumn": "transaction_id"
        }
      ]
    },
    {
      "table": "budgets",
      "unique": "budget_id",
      "foreignKeys": []
    },
    {
      "table": "receivables",
      "unique": "receivable_id",
      "foreignKeys": [
        {
          "column": "transaction_id",
          "table": "bank",
          "targetColumn": "transaction_id"
        }
      ]
    }
  ]
}
