{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://seedtactics.com/schemas/flexplan",
  "title": "SeedTactic FlexPlan JSON",
  "type": "object",
  "oneOf": [{ "$ref": "#/$defs/FlexProject" }],
  "$defs": {
    "FlexPlan": {
      "type": "object",
      "required": [
        "Parts",
        "LaborTeams",
        "CellEfficiency",
        "ExpectedCartTravelTime",
        "ExpectedRotarySwapTime"
      ],
      "properties": {
        "Parts": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/FlexPart"
          }
        },
        "LaborTeams": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/FlexLaborTeam"
          }
        },
        "NumLoadStations": {
          "type": "integer",
          "format": "int32"
        },
        "MachineNumbers": {
          "type": "object",
          "additionalProperties": {
            "type": "array",
            "items": {
              "type": "integer",
              "format": "int32"
            }
          }
        },
        "CellEfficiency": {
          "type": "number",
          "format": "double"
        },
        "ExpectedCartTravelTime": {
          "type": "string",
          "format": "time-span"
        },
        "ExpectedRotarySwapTime": {
          "type": "string",
          "format": "time-span"
        },
        "InspectionTypes": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/FlexInspectionType"
          }
        },
        "SeedtacticPlanningToken": {
          "type": "string"
        }
      }
    },
    "FlexProject": {
      "allOf": [
        {
          "$ref": "#/$defs/FlexPlan"
        },
        {
          "type": "object",
          "properties": {
            "PalletsInKanbansAutoGenerated": {
              "type": "boolean"
            },
            "Kanbans": {
              "type": "object",
              "additionalProperties": {
                "type": "array",
                "items": {
                  "type": "integer",
                  "format": "int32"
                }
              }
            },
            "MachineRouting": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "OrderSnapshots": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/FlexOrderSnapshot"
              }
            },
            "ForecastDemand": {
              "$ref": "#/$defs/FlexForecastDemand"
            },
            "CostInputs": {
              "$ref": "#/$defs/FlexCostInputs"
            },
            "AllocationAlgorithm": {
              "type": "string"
            }
          }
        }
      ]
    },
    "FlexPart": {
      "type": "object",
      "required": ["Name", "Readiness", "Processes", "Wash"],
      "properties": {
        "Name": {
          "type": "string"
        },
        "Readiness": {
          "$ref": "#/$defs/PartReadiness"
        },
        "Processes": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/FlexProcess"
          }
        },
        "Wash": {
          "type": "boolean"
        },
        "ExpectedWashTime": {
          "type": "string",
          "format": "time-span"
        },
        "GroupColor": {
          "type": "string"
        }
      }
    },
    "PartReadiness": {
      "type": "string",
      "enum": ["ProductionReady", "ProveOutOnly"]
    },
    "FlexProcess": {
      "type": "object",
      "required": ["ProcessNumber", "Paths"],
      "properties": {
        "ProcessNumber": {
          "type": "integer",
          "format": "int32"
        },
        "Paths": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/FlexPath"
          }
        }
      }
    },
    "FlexPath": {
      "type": "object",
      "required": [
        "LoadStations",
        "ExpectedLoadTime",
        "Stops",
        "UnloadStations",
        "ExpectedUnloadTime",
        "Pallets",
        "Face",
        "QuantityOnFace"
      ],
      "properties": {
        "LoadStations": {
          "type": "array",
          "items": {
            "type": "integer",
            "format": "int32"
          }
        },
        "ExpectedLoadTime": {
          "type": "string",
          "format": "time-span"
        },
        "Stops": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/FlexRouteStop"
          }
        },
        "UnloadStations": {
          "type": "array",
          "items": {
            "type": "integer",
            "format": "int32"
          }
        },
        "ExpectedUnloadTime": {
          "type": "string",
          "format": "time-span"
        },
        "Pallets": {
          "type": "array",
          "items": {
            "type": "integer",
            "format": "int32"
          }
        },
        "Fixture": {
          "type": "string"
        },
        "Face": {
          "type": "integer",
          "format": "int32"
        },
        "QuantityOnFace": {
          "type": "integer",
          "format": "int32"
        },
        "InputQueue": {
          "type": "string"
        },
        "OutputQueue": {
          "type": "string"
        },
        "Casting": {
          "type": "string"
        },
        "Inspections": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/FlexInspection"
          }
        }
      }
    },
    "FlexRouteStop": {
      "type": "object",
      "required": ["MachineGroup", "Program", "Machines"],
      "properties": {
        "MachineGroup": {
          "type": "string"
        },
        "Program": {
          "type": "string"
        },
        "Revision": {
          "type": "integer",
          "format": "int64"
        },
        "Machines": {
          "type": "array",
          "items": {
            "type": "integer",
            "format": "int32"
          }
        },
        "ExpectedCycleTime": {
          "type": "string",
          "format": "time-span"
        }
      }
    },
    "FlexInspection": {
      "type": "object",
      "required": ["InspectionType"],
      "properties": {
        "InspectionType": {
          "type": "string"
        },
        "MaxVal": {
          "type": "integer",
          "format": "int32"
        },
        "TimeInterval": {
          "type": "string",
          "format": "time-span"
        },
        "RandomFreq": {
          "type": "number",
          "format": "double"
        },
        "ExpectedInspectionTime": {
          "type": "string",
          "format": "time-span"
        }
      }
    },
    "FlexInspectionType": {
      "type": "object",
      "required": ["InspectionType"],
      "properties": {
        "InspectionType": {
          "type": "string"
        },
        "DuringLoadOfProc": {
          "type": "integer",
          "format": "int32"
        },
        "DuringUnloadOfProc": {
          "type": "integer",
          "format": "int32"
        },
        "AfterUnloadOfProc": {
          "type": "integer",
          "format": "int32"
        },
        "AfterFinalProcess": {
          "type": "boolean"
        },
        "DefaultMaxVal": {
          "type": "integer",
          "format": "int32"
        },
        "DefaultTimeInterval": {
          "type": "string",
          "format": "time-span"
        },
        "DefaultRandomFreq": {
          "type": "number",
          "format": "double"
        },
        "Team": {
          "type": "string"
        }
      }
    },
    "FlexLaborTeam": {
      "type": "object",
      "required": ["TeamName", "NumberOfOperators", "LoadStations"],
      "properties": {
        "TeamName": {
          "type": "string"
        },
        "NumberOfOperators": {
          "type": "integer",
          "format": "int32"
        },
        "LoadStations": {
          "type": "array",
          "items": {
            "type": "integer",
            "format": "int32"
          }
        }
      }
    },
    "FlexOrderSnapshot": {
      "type": "object",
      "required": ["LastEditTime", "Description"],
      "properties": {
        "Name": {
          "type": "string"
        },
        "LastEditTime": {
          "type": "string",
          "format": "date-time"
        },
        "Description": {
          "type": "string"
        },
        "StartDate": {
          "type": "string",
          "format": "date"
        },
        "Horizon": {
          "$ref": "/schemas/allocate#/$defs/AllocateHorizon"
        },
        "Orders": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/FlexOrder"
          }
        },
        "Parts": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/FlexPartDemand"
          }
        }
      }
    },
    "FlexOrder": {
      "type": "object",
      "required": ["Part", "Quantity", "Priority", "DueDate"],
      "properties": {
        "Part": {
          "type": "string"
        },
        "PathColors": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "Quantity": {
          "type": "integer",
          "format": "int32"
        },
        "Priority": {
          "type": "integer",
          "format": "int32"
        },
        "DueDate": {
          "type": "string",
          "format": "date-time"
        },
        "OrderId": {
          "type": "string"
        }
      }
    },
    "FlexPartDemand": {
      "type": "object",
      "required": ["Part", "Quantity"],
      "properties": {
        "Part": {
          "type": "string"
        },
        "PathColor": {
          "type": "string"
        },
        "Quantity": {
          "type": "integer",
          "format": "int32"
        },
        "Priority": {
          "type": "integer",
          "format": "int32"
        }
      }
    },
    "FlexForecastDemand": {
      "type": "object",
      "required": ["Horizon", "Parts"],
      "properties": {
        "Horizon": {
          "$ref": "#/$defs/FlexForecastHorizon"
        },
        "Parts": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/FlexForecastPartDemand"
          }
        }
      }
    },
    "FlexForecastHorizon": {
      "type": "object",
      "required": ["HoursPerDay", "DaysPerWeek", "Length"],
      "properties": {
        "HoursPerDay": {
          "type": "integer",
          "format": "int32"
        },
        "DaysPerWeek": {
          "type": "integer",
          "format": "int32"
        },
        "Length": {
          "$ref": "#/$defs/FlexForecastHorizonLength"
        }
      }
    },
    "FlexForecastHorizonLength": {
      "type": "string",
      "enum": ["FourWeeks", "TwentySixWeeks", "FiftyTwoWeeks"]
    },
    "FlexForecastPartDemand": {
      "type": "object",
      "required": ["Quantity"],
      "properties": {
        "Quantity": {
          "type": "integer",
          "format": "int32"
        },
        "Priority": {
          "type": "integer",
          "format": "int32"
        }
      }
    },
    "FlexCostInputs": {
      "type": "object",
      "required": ["machineCostPerYear"],
      "properties": {
        "automationCostPerYear": {
          "type": "number",
          "format": "decimal"
        },
        "laborCostPerYear": {
          "type": "number",
          "format": "decimal"
        },
        "machineCostPerYear": {
          "type": "object",
          "additionalProperties": {
            "type": "number",
            "format": "decimal"
          }
        }
      }
    }
  }
}