{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Willow Community Fund 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": {
        "campaigns": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {}
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "campaign_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "name": {
                    "type": "string"
                  },
                  "goal": {
                    "type": "number"
                  }
                },
                "required": [
                  "campaign_id",
                  "name",
                  "goal"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "donors": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {}
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "donor_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "name": {
                    "type": "string"
                  }
                },
                "required": [
                  "donor_id",
                  "name"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "pledges": {
          "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": {
                  "pledge_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "campaign_id": {
                    "type": "string"
                  },
                  "donor_id": {
                    "type": "string"
                  },
                  "pledged": {
                    "type": "number"
                  },
                  "received": {
                    "type": "number"
                  },
                  "remaining": {
                    "type": "number"
                  }
                },
                "required": [
                  "pledge_id",
                  "campaign_id",
                  "donor_id",
                  "pledged",
                  "received",
                  "remaining"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "grants": {
          "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": {
                  "grant_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "campaign_id": {
                    "type": "string"
                  },
                  "funder": {
                    "type": "string"
                  },
                  "requested": {
                    "type": "number"
                  },
                  "awarded": {
                    "type": "number"
                  },
                  "status": {
                    "type": "string"
                  }
                },
                "required": [
                  "grant_id",
                  "campaign_id",
                  "funder",
                  "requested",
                  "awarded",
                  "status"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "volunteers": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {}
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "volunteer_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "name": {
                    "type": "string"
                  },
                  "role": {
                    "type": "string"
                  }
                },
                "required": [
                  "volunteer_id",
                  "name",
                  "role"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "events": {
          "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": {
                  "event_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "campaign_id": {
                    "type": "string"
                  },
                  "date": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  },
                  "capacity": {
                    "type": "number"
                  }
                },
                "required": [
                  "event_id",
                  "campaign_id",
                  "date",
                  "name",
                  "capacity"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "volunteer_shifts": {
          "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": {
                  "shift_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "event_id": {
                    "type": "string"
                  },
                  "volunteer_id": {
                    "type": "string"
                  },
                  "hours": {
                    "type": "number"
                  }
                },
                "required": [
                  "shift_id",
                  "event_id",
                  "volunteer_id",
                  "hours"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "impact": {
          "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": {
                  "impact_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "event_id": {
                    "type": "string"
                  },
                  "measure": {
                    "type": "string"
                  },
                  "count": {
                    "type": "number"
                  },
                  "unit": {
                    "type": "string"
                  }
                },
                "required": [
                  "impact_id",
                  "event_id",
                  "measure",
                  "count",
                  "unit"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "campaigns",
        "donors",
        "pledges",
        "grants",
        "volunteers",
        "events",
        "volunteer_shifts",
        "impact"
      ],
      "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": "campaigns",
      "unique": "campaign_id",
      "foreignKeys": []
    },
    {
      "table": "donors",
      "unique": "donor_id",
      "foreignKeys": []
    },
    {
      "table": "pledges",
      "unique": "pledge_id",
      "foreignKeys": [
        {
          "column": "campaign_id",
          "table": "campaigns",
          "targetColumn": "campaign_id"
        },
        {
          "column": "donor_id",
          "table": "donors",
          "targetColumn": "donor_id"
        }
      ]
    },
    {
      "table": "grants",
      "unique": "grant_id",
      "foreignKeys": [
        {
          "column": "campaign_id",
          "table": "campaigns",
          "targetColumn": "campaign_id"
        }
      ]
    },
    {
      "table": "volunteers",
      "unique": "volunteer_id",
      "foreignKeys": []
    },
    {
      "table": "events",
      "unique": "event_id",
      "foreignKeys": [
        {
          "column": "campaign_id",
          "table": "campaigns",
          "targetColumn": "campaign_id"
        }
      ]
    },
    {
      "table": "volunteer_shifts",
      "unique": "shift_id",
      "foreignKeys": [
        {
          "column": "event_id",
          "table": "events",
          "targetColumn": "event_id"
        },
        {
          "column": "volunteer_id",
          "table": "volunteers",
          "targetColumn": "volunteer_id"
        }
      ]
    },
    {
      "table": "impact",
      "unique": "impact_id",
      "foreignKeys": [
        {
          "column": "event_id",
          "table": "events",
          "targetColumn": "event_id"
        }
      ]
    }
  ]
}
