{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Juniper Workspace Cloud 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": {
        "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"
                  },
                  "plan": {
                    "type": "string"
                  },
                  "monthly_rate": {
                    "type": "number"
                  },
                  "status": {
                    "type": "string"
                  },
                  "active_mrr": {
                    "type": "number"
                  }
                },
                "required": [
                  "account_id",
                  "name",
                  "plan",
                  "monthly_rate",
                  "status",
                  "active_mrr"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "invoices": {
          "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": {
                  "invoice_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "account_id": {
                    "type": "string"
                  },
                  "month": {
                    "type": "string"
                  },
                  "amount": {
                    "type": "number"
                  },
                  "paid": {
                    "type": "number"
                  },
                  "outstanding": {
                    "type": "number"
                  }
                },
                "required": [
                  "invoice_id",
                  "account_id",
                  "month",
                  "amount",
                  "paid",
                  "outstanding"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "usage": {
          "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": {
                  "usage_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "account_id": {
                    "type": "string"
                  },
                  "date": {
                    "type": "string"
                  },
                  "exports": {
                    "type": "number"
                  },
                  "storage_mb": {
                    "type": "number"
                  }
                },
                "required": [
                  "usage_id",
                  "account_id",
                  "date",
                  "exports",
                  "storage_mb"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "tickets": {
          "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": {
                  "ticket_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "account_id": {
                    "type": "string"
                  },
                  "opened_date": {
                    "type": "string"
                  },
                  "category": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string"
                  },
                  "priority": {
                    "type": "string"
                  },
                  "first_response_hours": {
                    "type": "number"
                  },
                  "resolution_hours": {
                    "type": "number"
                  }
                },
                "required": [
                  "ticket_id",
                  "account_id",
                  "opened_date",
                  "category",
                  "status",
                  "priority",
                  "first_response_hours",
                  "resolution_hours"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "ticket_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
                  },
                  "ticket_id": {
                    "type": "string"
                  },
                  "sequence": {
                    "type": "number"
                  },
                  "event": {
                    "type": "string"
                  },
                  "text": {
                    "type": "string"
                  }
                },
                "required": [
                  "event_id",
                  "ticket_id",
                  "sequence",
                  "event",
                  "text"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "service_reports": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {}
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "report_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "category": {
                    "type": "string"
                  },
                  "opened": {
                    "type": "number"
                  },
                  "resolved": {
                    "type": "number"
                  },
                  "response_hours_sum": {
                    "type": "number"
                  }
                },
                "required": [
                  "report_id",
                  "category",
                  "opened",
                  "resolved",
                  "response_hours_sum"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "accounts",
        "invoices",
        "usage",
        "tickets",
        "ticket_events",
        "service_reports"
      ],
      "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": "accounts",
      "unique": "account_id",
      "foreignKeys": []
    },
    {
      "table": "invoices",
      "unique": "invoice_id",
      "foreignKeys": [
        {
          "column": "account_id",
          "table": "accounts",
          "targetColumn": "account_id"
        }
      ]
    },
    {
      "table": "usage",
      "unique": "usage_id",
      "foreignKeys": [
        {
          "column": "account_id",
          "table": "accounts",
          "targetColumn": "account_id"
        }
      ]
    },
    {
      "table": "tickets",
      "unique": "ticket_id",
      "foreignKeys": [
        {
          "column": "account_id",
          "table": "accounts",
          "targetColumn": "account_id"
        }
      ]
    },
    {
      "table": "ticket_events",
      "unique": "event_id",
      "foreignKeys": [
        {
          "column": "ticket_id",
          "table": "tickets",
          "targetColumn": "ticket_id"
        }
      ]
    },
    {
      "table": "service_reports",
      "unique": "report_id",
      "foreignKeys": []
    }
  ]
}
