{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agrowknow.com/farm-fuel/integrations/scenario-v1.schema.json",
  "title": "AgrowKnow Farm Fuel scenario, version 1",
  "description": "Canonical portable scenario format. Quantities may be null for unknown inputs; null is not zero. The importer performs structural validation, and the calculator separately checks whether an estimate is complete.",
  "type": "object",
  "properties": {
    "app": {
      "const": "agrowknow-farm-fuel"
    },
    "version": {
      "const": 1
    },
    "savedAt": {
      "type": "string",
      "format": "date-time"
    },
    "state": {
      "$ref": "#/$defs/state"
    }
  },
  "required": [
    "app",
    "version",
    "savedAt",
    "state"
  ],
  "additionalProperties": false,
  "$defs": {
    "quantity": {
      "type": [
        "number",
        "null"
      ],
      "minimum": 0,
      "maximum": 1000000000
    },
    "fuels": {
      "type": "object",
      "properties": {
        "offroad": {
          "$ref": "#/$defs/quantity"
        },
        "road": {
          "$ref": "#/$defs/quantity"
        },
        "propane": {
          "$ref": "#/$defs/quantity"
        }
      },
      "required": [
        "offroad",
        "road",
        "propane"
      ],
      "additionalProperties": false
    },
    "overrides": {
      "type": "object",
      "properties": {
        "offroad": {
          "anyOf": [
            {
              "$ref": "#/$defs/quantity"
            },
            {
              "const": ""
            }
          ]
        },
        "road": {
          "anyOf": [
            {
              "$ref": "#/$defs/quantity"
            },
            {
              "const": ""
            }
          ]
        },
        "propane": {
          "anyOf": [
            {
              "$ref": "#/$defs/quantity"
            },
            {
              "const": ""
            }
          ]
        }
      },
      "required": [
        "offroad",
        "road",
        "propane"
      ],
      "additionalProperties": false
    },
    "operation": {
      "type": "object",
      "properties": {
        "key": {
          "enum": [
            "chisel",
            "cultivate",
            "vertical",
            "strip",
            "ripper",
            "plant",
            "plantNotill",
            "spray",
            "dryFertilizer",
            "anhydrous",
            "liquidN",
            "combineCorn",
            "combineSoy",
            "cartCorn",
            "cartSoy",
            "custom"
          ]
        },
        "name": {
          "type": "string",
          "maxLength": 90,
          "description": "The importer additionally caps names at 90 JavaScript UTF-16 code units, so some emoji count as two units."
        },
        "rate": {
          "$ref": "#/$defs/quantity"
        },
        "passes": {
          "$ref": "#/$defs/quantity"
        },
        "coverage": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 100
        }
      },
      "required": [
        "key",
        "name",
        "rate",
        "passes",
        "coverage"
      ],
      "additionalProperties": false
    },
    "crop": {
      "type": "object",
      "properties": {
        "acres": {
          "$ref": "#/$defs/quantity"
        },
        "yield": {
          "$ref": "#/$defs/quantity"
        },
        "system": {
          "enum": [
            "conventional",
            "reduced",
            "notill"
          ]
        },
        "programs": {
          "type": "object",
          "properties": {
            "conventional": {
              "type": "array",
              "maxItems": 250,
              "items": {
                "$ref": "#/$defs/operation"
              }
            },
            "reduced": {
              "type": "array",
              "maxItems": 250,
              "items": {
                "$ref": "#/$defs/operation"
              }
            },
            "notill": {
              "type": "array",
              "maxItems": 250,
              "items": {
                "$ref": "#/$defs/operation"
              }
            }
          },
          "required": [
            "conventional",
            "reduced",
            "notill"
          ],
          "additionalProperties": false
        },
        "hauling": {
          "type": "object",
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "share": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0,
              "maximum": 100
            },
            "distance": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0,
              "maximum": 1000000000
            },
            "capacity": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0,
              "maximum": 1000000000
            },
            "mpg": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0,
              "maximum": 1000000000
            },
            "idleMinutes": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0,
              "maximum": 1000000000
            },
            "idleRate": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0,
              "maximum": 1000000000
            }
          },
          "required": [
            "enabled",
            "share",
            "distance",
            "capacity",
            "mpg",
            "idleMinutes",
            "idleRate"
          ],
          "additionalProperties": false
        },
        "irrigation": {
          "type": "object",
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "share": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0,
              "maximum": 100
            },
            "gallons": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0,
              "maximum": 1000000000
            }
          },
          "required": [
            "enabled",
            "share",
            "gallons"
          ],
          "additionalProperties": false
        },
        "drying": {
          "type": "object",
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "share": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0,
              "maximum": 100
            },
            "initial": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0,
              "maximum": 100
            },
            "target": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0,
              "maximum": 100
            },
            "rate": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0,
              "maximum": 1000000000
            }
          },
          "required": [
            "enabled",
            "share",
            "initial",
            "target",
            "rate"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "acres",
        "yield",
        "system",
        "programs",
        "hauling",
        "irrigation",
        "drying"
      ],
      "additionalProperties": false
    },
    "state": {
      "type": "object",
      "properties": {
        "crop": {
          "enum": [
            "corn",
            "soybeans"
          ]
        },
        "crops": {
          "type": "object",
          "properties": {
            "corn": {
              "$ref": "#/$defs/crop"
            },
            "soybeans": {
              "$ref": "#/$defs/crop"
            }
          },
          "required": [
            "corn",
            "soybeans"
          ],
          "additionalProperties": false
        },
        "prices": {
          "$ref": "#/$defs/fuels"
        },
        "baseline": {
          "type": "object",
          "properties": {
            "year": {
              "type": "integer",
              "minimum": 2019,
              "maximum": 9999
            },
            "month": {
              "type": "integer",
              "minimum": 1,
              "maximum": 12
            },
            "overrides": {
              "$ref": "#/$defs/overrides"
            }
          },
          "required": [
            "year",
            "month",
            "overrides"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "crop",
        "crops",
        "prices",
        "baseline"
      ],
      "additionalProperties": false
    }
  }
}
