{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "draft": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "proposal"
            },
            "title": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            },
            "description": {
              "type": "string",
              "maxLength": 400
            },
            "currency": {
              "type": "string",
              "pattern": "^[A-Z]{3}$"
            },
            "inputs": {
              "minItems": 1,
              "maxItems": 12,
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "key": {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9_]{0,31}$"
                  },
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "kind": {
                    "type": "string",
                    "enum": [
                      "number",
                      "percent",
                      "count",
                      "money",
                      "money_per_item",
                      "hours",
                      "money_per_hour",
                      "length",
                      "area",
                      "volume"
                    ]
                  },
                  "integer": {
                    "type": "boolean"
                  },
                  "default": {
                    "type": "string",
                    "pattern": "^[+-]?(?:\\d{1,15}(?:\\.\\d{1,12})?|\\.\\d{1,12})$"
                  },
                  "min": {
                    "type": "string",
                    "pattern": "^[+-]?(?:\\d{1,15}(?:\\.\\d{1,12})?|\\.\\d{1,12})$"
                  },
                  "max": {
                    "type": "string",
                    "pattern": "^[+-]?(?:\\d{1,15}(?:\\.\\d{1,12})?|\\.\\d{1,12})$"
                  }
                },
                "required": [
                  "key",
                  "label",
                  "kind",
                  "integer",
                  "default",
                  "min",
                  "max"
                ],
                "additionalProperties": false
              }
            },
            "output": {
              "type": "object",
              "properties": {
                "label": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100
                },
                "expression": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 2000
                },
                "kind": {
                  "type": "string",
                  "enum": [
                    "number",
                    "percent",
                    "count",
                    "money",
                    "money_per_item",
                    "hours",
                    "money_per_hour",
                    "length",
                    "area",
                    "volume"
                  ]
                },
                "decimals": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 12
                },
                "rounding": {
                  "type": "string",
                  "enum": [
                    "half-up",
                    "half-even"
                  ]
                }
              },
              "required": [
                "label",
                "expression",
                "kind",
                "decimals",
                "rounding"
              ],
              "additionalProperties": false
            },
            "assumptions": {
              "minItems": 1,
              "maxItems": 10,
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1,
                "maxLength": 400
              }
            }
          },
          "required": [
            "kind",
            "title",
            "description",
            "currency",
            "inputs",
            "output",
            "assumptions"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "clarification"
            },
            "questions": {
              "minItems": 1,
              "maxItems": 5,
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1,
                "maxLength": 400
              }
            }
          },
          "required": [
            "kind",
            "questions"
          ],
          "additionalProperties": false
        }
      ]
    }
  },
  "required": [
    "draft"
  ],
  "additionalProperties": false,
  "$id": "https://usecalculator.app/specs/model-proposal.schema.json"
}
