{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Cobalt Operations Team 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": {
        "employees": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {}
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "employee_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "name": {
                    "type": "string"
                  },
                  "department": {
                    "type": "string"
                  },
                  "hourly_rate": {
                    "type": "number"
                  },
                  "active": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "employee_id",
                  "name",
                  "department",
                  "hourly_rate",
                  "active"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "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
                  },
                  "employee_id": {
                    "type": "string"
                  },
                  "date": {
                    "type": "string"
                  },
                  "paid_hours": {
                    "type": "number"
                  },
                  "hourly_rate": {
                    "type": "number"
                  },
                  "base_pay": {
                    "type": "number"
                  }
                },
                "required": [
                  "shift_id",
                  "employee_id",
                  "date",
                  "paid_hours",
                  "hourly_rate",
                  "base_pay"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "leave_requests": {
          "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": {
                  "request_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "employee_id": {
                    "type": "string"
                  },
                  "date": {
                    "type": "string"
                  },
                  "hours": {
                    "type": "number"
                  },
                  "status": {
                    "type": "string"
                  }
                },
                "required": [
                  "request_id",
                  "employee_id",
                  "date",
                  "hours",
                  "status"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "service_slots": {
          "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": {
                  "slot_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "employee_id": {
                    "type": "string"
                  },
                  "date": {
                    "type": "string"
                  },
                  "start_time": {
                    "type": "string"
                  },
                  "capacity": {
                    "type": "number"
                  }
                },
                "required": [
                  "slot_id",
                  "employee_id",
                  "date",
                  "start_time",
                  "capacity"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "service_bookings": {
          "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": {
                  "booking_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "slot_id": {
                    "type": "string"
                  },
                  "customer": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string"
                  },
                  "occupied": {
                    "type": "number"
                  }
                },
                "required": [
                  "booking_id",
                  "slot_id",
                  "customer",
                  "status",
                  "occupied"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "employees",
        "shifts",
        "leave_requests",
        "service_slots",
        "service_bookings"
      ],
      "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": "employees",
      "unique": "employee_id",
      "foreignKeys": []
    },
    {
      "table": "shifts",
      "unique": "shift_id",
      "foreignKeys": [
        {
          "column": "employee_id",
          "table": "employees",
          "targetColumn": "employee_id"
        }
      ]
    },
    {
      "table": "leave_requests",
      "unique": "request_id",
      "foreignKeys": [
        {
          "column": "employee_id",
          "table": "employees",
          "targetColumn": "employee_id"
        }
      ]
    },
    {
      "table": "service_slots",
      "unique": "slot_id",
      "foreignKeys": [
        {
          "column": "employee_id",
          "table": "employees",
          "targetColumn": "employee_id"
        }
      ]
    },
    {
      "table": "service_bookings",
      "unique": "booking_id",
      "foreignKeys": [
        {
          "column": "slot_id",
          "table": "service_slots",
          "targetColumn": "slot_id"
        }
      ]
    }
  ]
}
