{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Fieldnote Supply Shop 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": {
        "products": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {}
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "product_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "sku": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  },
                  "category": {
                    "type": "string"
                  },
                  "unit_price": {
                    "type": "number"
                  },
                  "unit_cost": {
                    "type": "number"
                  },
                  "stock": {
                    "type": "number"
                  },
                  "active": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "product_id",
                  "sku",
                  "name",
                  "category",
                  "unit_price",
                  "unit_cost",
                  "stock",
                  "active"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "customers": {
          "type": "object",
          "properties": {
            "primaryKey": {
              "type": "string"
            },
            "foreignKeys": {
              "type": "array",
              "items": {}
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "customer_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "name": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string"
                  }
                },
                "required": [
                  "customer_id",
                  "name",
                  "email"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "orders": {
          "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": {
                  "order_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "date": {
                    "type": "string"
                  },
                  "customer_id": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string"
                  },
                  "currency": {
                    "type": "string"
                  }
                },
                "required": [
                  "order_id",
                  "date",
                  "customer_id",
                  "status",
                  "currency"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "order_lines": {
          "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": {
                  "line_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "order_id": {
                    "type": "string"
                  },
                  "product_id": {
                    "type": "string"
                  },
                  "quantity": {
                    "type": "number"
                  },
                  "unit_price": {
                    "type": "number"
                  },
                  "line_total": {
                    "type": "number"
                  },
                  "variant_id": {
                    "type": "string"
                  }
                },
                "required": [
                  "line_id",
                  "order_id",
                  "product_id",
                  "quantity",
                  "unit_price",
                  "line_total",
                  "variant_id"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "payments": {
          "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": {
                  "payment_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "order_id": {
                    "type": "string"
                  },
                  "amount": {
                    "type": "number"
                  },
                  "refunded": {
                    "type": "number"
                  },
                  "currency": {
                    "type": "string"
                  }
                },
                "required": [
                  "payment_id",
                  "order_id",
                  "amount",
                  "refunded",
                  "currency"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "variants": {
          "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": {
                  "variant_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "product_id": {
                    "type": "string"
                  },
                  "sku": {
                    "type": "string"
                  },
                  "option_name": {
                    "type": "string"
                  },
                  "option_value": {
                    "type": "string"
                  },
                  "stock": {
                    "type": "number"
                  },
                  "unit_price": {
                    "type": "number"
                  }
                },
                "required": [
                  "variant_id",
                  "product_id",
                  "sku",
                  "option_name",
                  "option_value",
                  "stock",
                  "unit_price"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "discounts": {
          "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": {
                  "discount_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "order_id": {
                    "type": "string"
                  },
                  "code": {
                    "type": "string"
                  },
                  "amount": {
                    "type": "number"
                  },
                  "currency": {
                    "type": "string"
                  }
                },
                "required": [
                  "discount_id",
                  "order_id",
                  "code",
                  "amount",
                  "currency"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "returns": {
          "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": {
                  "return_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "line_id": {
                    "type": "string"
                  },
                  "quantity": {
                    "type": "number"
                  },
                  "refund_amount": {
                    "type": "number"
                  },
                  "reason": {
                    "type": "string"
                  },
                  "restock": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "return_id",
                  "line_id",
                  "quantity",
                  "refund_amount",
                  "reason",
                  "restock"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        },
        "merchandising": {
          "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": {
                  "placement_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "product_id": {
                    "type": "string"
                  },
                  "collection": {
                    "type": "string"
                  },
                  "display_order": {
                    "type": "number"
                  },
                  "start_date": {
                    "type": "string"
                  },
                  "end_date": {
                    "type": "string"
                  }
                },
                "required": [
                  "placement_id",
                  "product_id",
                  "collection",
                  "display_order",
                  "start_date",
                  "end_date"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "primaryKey",
            "foreignKeys",
            "rows"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "products",
        "customers",
        "orders",
        "order_lines",
        "payments",
        "variants",
        "discounts",
        "returns",
        "merchandising"
      ],
      "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": "products",
      "unique": "product_id",
      "foreignKeys": []
    },
    {
      "table": "customers",
      "unique": "customer_id",
      "foreignKeys": []
    },
    {
      "table": "orders",
      "unique": "order_id",
      "foreignKeys": [
        {
          "column": "customer_id",
          "table": "customers",
          "targetColumn": "customer_id"
        }
      ]
    },
    {
      "table": "order_lines",
      "unique": "line_id",
      "foreignKeys": [
        {
          "column": "order_id",
          "table": "orders",
          "targetColumn": "order_id"
        },
        {
          "column": "product_id",
          "table": "products",
          "targetColumn": "product_id"
        },
        {
          "column": "variant_id",
          "table": "variants",
          "targetColumn": "variant_id"
        }
      ]
    },
    {
      "table": "payments",
      "unique": "payment_id",
      "foreignKeys": [
        {
          "column": "order_id",
          "table": "orders",
          "targetColumn": "order_id"
        }
      ]
    },
    {
      "table": "variants",
      "unique": "variant_id",
      "foreignKeys": [
        {
          "column": "product_id",
          "table": "products",
          "targetColumn": "product_id"
        }
      ]
    },
    {
      "table": "discounts",
      "unique": "discount_id",
      "foreignKeys": [
        {
          "column": "order_id",
          "table": "orders",
          "targetColumn": "order_id"
        }
      ]
    },
    {
      "table": "returns",
      "unique": "return_id",
      "foreignKeys": [
        {
          "column": "line_id",
          "table": "order_lines",
          "targetColumn": "line_id"
        }
      ]
    },
    {
      "table": "merchandising",
      "unique": "placement_id",
      "foreignKeys": [
        {
          "column": "product_id",
          "table": "products",
          "targetColumn": "product_id"
        }
      ]
    }
  ]
}
