{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Fieldnote Learning Centre 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": {
        "courses": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {}
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "course_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "name": {
                    "type": "string"
                  },
                  "capacity": {
                    "type": "number"
                  },
                  "pass_score": {
                    "type": "number"
                  }
                },
                "required": [
                  "course_id",
                  "name",
                  "capacity",
                  "pass_score"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "learners": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {}
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "learner_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "name": {
                    "type": "string"
                  }
                },
                "required": [
                  "learner_id",
                  "name"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "enrollments": {
          "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": {
                  "enrollment_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "learner_id": {
                    "type": "string"
                  },
                  "course_id": {
                    "type": "string"
                  },
                  "score": {
                    "type": "number"
                  },
                  "completed": {
                    "type": "boolean"
                  },
                  "passed": {
                    "type": "number"
                  }
                },
                "required": [
                  "enrollment_id",
                  "learner_id",
                  "course_id",
                  "score",
                  "completed",
                  "passed"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "attendance": {
          "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": {
                  "attendance_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "enrollment_id": {
                    "type": "string"
                  },
                  "session": {
                    "type": "number"
                  },
                  "date": {
                    "type": "string"
                  },
                  "present": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "attendance_id",
                  "enrollment_id",
                  "session",
                  "date",
                  "present"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "learning_materials": {
          "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": {
                  "material_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "course_id": {
                    "type": "string"
                  },
                  "title": {
                    "type": "string"
                  },
                  "format": {
                    "type": "string"
                  },
                  "content": {
                    "type": "string"
                  }
                },
                "required": [
                  "material_id",
                  "course_id",
                  "title",
                  "format",
                  "content"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "courses",
        "learners",
        "enrollments",
        "attendance",
        "learning_materials"
      ],
      "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": "courses",
      "unique": "course_id",
      "foreignKeys": []
    },
    {
      "table": "learners",
      "unique": "learner_id",
      "foreignKeys": []
    },
    {
      "table": "enrollments",
      "unique": "enrollment_id",
      "foreignKeys": [
        {
          "column": "learner_id",
          "table": "learners",
          "targetColumn": "learner_id"
        },
        {
          "column": "course_id",
          "table": "courses",
          "targetColumn": "course_id"
        }
      ]
    },
    {
      "table": "attendance",
      "unique": "attendance_id",
      "foreignKeys": [
        {
          "column": "enrollment_id",
          "table": "enrollments",
          "targetColumn": "enrollment_id"
        }
      ]
    },
    {
      "table": "learning_materials",
      "unique": "material_id",
      "foreignKeys": [
        {
          "column": "course_id",
          "table": "courses",
          "targetColumn": "course_id"
        }
      ]
    }
  ]
}
