{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Harbour House Stay 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": {
        "rooms": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {}
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "room_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "type": {
                    "type": "string"
                  },
                  "nightly_rate": {
                    "type": "number"
                  },
                  "available_nights": {
                    "type": "number"
                  }
                },
                "required": [
                  "room_id",
                  "type",
                  "nightly_rate",
                  "available_nights"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "stays": {
          "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": {
                  "stay_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "room_id": {
                    "type": "string"
                  },
                  "arrival": {
                    "type": "string"
                  },
                  "nights": {
                    "type": "number"
                  },
                  "nightly_rate": {
                    "type": "number"
                  },
                  "room_revenue": {
                    "type": "number"
                  }
                },
                "required": [
                  "stay_id",
                  "room_id",
                  "arrival",
                  "nights",
                  "nightly_rate",
                  "room_revenue"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "extras": {
          "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": {
                  "charge_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "stay_id": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  },
                  "quantity": {
                    "type": "number"
                  },
                  "unit_price": {
                    "type": "number"
                  },
                  "total": {
                    "type": "number"
                  }
                },
                "required": [
                  "charge_id",
                  "stay_id",
                  "description",
                  "quantity",
                  "unit_price",
                  "total"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "itineraries": {
          "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": {
                  "itinerary_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "stay_id": {
                    "type": "string"
                  },
                  "date": {
                    "type": "string"
                  },
                  "sequence": {
                    "type": "number"
                  },
                  "activity": {
                    "type": "string"
                  },
                  "location": {
                    "type": "string"
                  }
                },
                "required": [
                  "itinerary_id",
                  "stay_id",
                  "date",
                  "sequence",
                  "activity",
                  "location"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "event_resources": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {}
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "resource_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "name": {
                    "type": "string"
                  },
                  "capacity": {
                    "type": "number"
                  }
                },
                "required": [
                  "resource_id",
                  "name",
                  "capacity"
                ],
                "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
                  },
                  "name": {
                    "type": "string"
                  },
                  "date": {
                    "type": "string"
                  },
                  "resource_id": {
                    "type": "string"
                  },
                  "attendees": {
                    "type": "number"
                  },
                  "start_time": {
                    "type": "string"
                  },
                  "end_time": {
                    "type": "string"
                  }
                },
                "required": [
                  "event_id",
                  "name",
                  "date",
                  "resource_id",
                  "attendees",
                  "start_time",
                  "end_time"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "event_catering": {
          "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": {
                  "catering_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "event_id": {
                    "type": "string"
                  },
                  "meal": {
                    "type": "string"
                  },
                  "portions": {
                    "type": "number"
                  },
                  "unit_price": {
                    "type": "number"
                  },
                  "amount": {
                    "type": "number"
                  },
                  "currency": {
                    "type": "string"
                  }
                },
                "required": [
                  "catering_id",
                  "event_id",
                  "meal",
                  "portions",
                  "unit_price",
                  "amount",
                  "currency"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "rooms",
        "stays",
        "extras",
        "itineraries",
        "event_resources",
        "events",
        "event_catering"
      ],
      "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": {}
    }
  },
  "required": [
    "id",
    "slug",
    "title",
    "industry",
    "description",
    "workflows",
    "asOf",
    "source",
    "tables",
    "metrics",
    "chart",
    "notes"
  ],
  "additionalProperties": false,
  "x-relationalRules": [
    {
      "table": "rooms",
      "unique": "room_id",
      "foreignKeys": []
    },
    {
      "table": "stays",
      "unique": "stay_id",
      "foreignKeys": [
        {
          "column": "room_id",
          "table": "rooms",
          "targetColumn": "room_id"
        }
      ]
    },
    {
      "table": "extras",
      "unique": "charge_id",
      "foreignKeys": [
        {
          "column": "stay_id",
          "table": "stays",
          "targetColumn": "stay_id"
        }
      ]
    },
    {
      "table": "itineraries",
      "unique": "itinerary_id",
      "foreignKeys": [
        {
          "column": "stay_id",
          "table": "stays",
          "targetColumn": "stay_id"
        }
      ]
    },
    {
      "table": "event_resources",
      "unique": "resource_id",
      "foreignKeys": []
    },
    {
      "table": "events",
      "unique": "event_id",
      "foreignKeys": [
        {
          "column": "resource_id",
          "table": "event_resources",
          "targetColumn": "resource_id"
        }
      ]
    },
    {
      "table": "event_catering",
      "unique": "catering_id",
      "foreignKeys": [
        {
          "column": "event_id",
          "table": "events",
          "targetColumn": "event_id"
        }
      ]
    }
  ]
}
