{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://seedtactics.com/schemas/allocate",
  "title": "SeedTactic Allocation JSON",
  "type": "object",
  "oneOf": [
    {
      "$ref": "#/$defs/AllocateRequest"
    }
  ],
  "$defs": {
    "DowntimeUTCRange": {
      "type": "object",
      "required": ["StartOfDowntimeUTC", "EndOfDowntimeUTC"],
      "properties": {
        "StartOfDowntimeUTC": {
          "type": "string",
          "format": "date-time"
        },
        "EndOfDowntimeUTC": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "DayHorizon": {
      "type": "object",
      "required": ["HoursForDay", "DayStartOffset"],
      "properties": {
        "HoursForDay": {
          "type": "string",
          "format": "time-span"
        },
        "DayStartOffset": {
          "type": "string",
          "format": "time-span"
        }
      }
    },
    "AllocateHorizon": {
      "type": "object",
      "required": ["NumWeeks"],
      "properties": {
        "NumWeeks": {
          "type": "integer",
          "format": "int32"
        },
        "Timezone": {
          "type": "string"
        },
        "DowntimeUTC": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/DowntimeUTCRange"
          }
        },
        "DaysOfWeek": {
          "type": "object",
          "propertyNames": {
            "format": "dayofweek"
          },
          "additionalProperties": {
            "$ref": "#/$defs/DayHorizon"
          }
        }
      }
    },
    "AllocateRequest": {
      "type": "object",
      "required": ["ScheduleId", "StartUTC", "EndUTC", "FlexPlan"],
      "properties": {
        "ScheduleId": {
          "type": "string"
        },
        "StartUTC": {
          "type": "string",
          "format": "date-time"
        },
        "EndUTC": {
          "type": "string",
          "format": "date-time"
        },
        "PreviousSchedule": {
          "$ref": "/schemas/fms-insight#/components/schemas/MostRecentSchedule"
        },
        "CurrentStatus": {
          "$ref": "/schemas/fms-insight#/components/schemas/CurrentStatus"
        },
        "UnscheduledBookings": {
          "type": "array",
          "items": {
            "$ref": "/schemas/orders#/$defs/Booking"
          }
        },
        "ScheduledParts": {
          "type": "array",
          "items": {
            "$ref": "/schemas/orders#/$defs/ScheduledPartWithoutBooking"
          }
        },
        "FlexPlan": {
          "$ref": "/schemas/flexplan#/$defs/FlexPlan"
        },
        "Horizon": {
          "$ref": "#/$defs/AllocateHorizon"
        }
      }
    },
    "SimulatedPartCompleted": {
      "type": "object",
      "required": ["Day", "Part", "Process", "Path", "Completed"],
      "properties": {
        "Day": {
          "type": "string",
          "format": "date"
        },
        "Part": {
          "type": "string"
        },
        "Color": {
          "type": "string"
        },
        "Completed": {
          "type": "array",
          "items": {
            "type": "array",
            "items": {
              "type": "integer",
              "format": "int32"
            }
          }
        }
      }
    },
    "SimulatedMachine": {
      "type": "object",
      "required": ["Hour", "StationGroup", "StationNum"],
      "properties": {
        "Hour": {
          "type": "integer",
          "format": "int64"
        },
        "StationGroup": {
          "type": "string"
        },
        "StationNum": {
          "type": "integer",
          "format": "int32"
        },
        "RotarySwaps": {
          "type": "integer",
          "format": "int32"
        },
        "Inbound": {
          "type": "string",
          "format": "time-span"
        },
        "Use": {
          "type": "string",
          "format": "time-span"
        },
        "Outbound": {
          "type": "string",
          "format": "time-span"
        }
      }
    },
    "SimulatedLoadStation": {
      "type": "object",
      "required": ["Hour", "LoadStation"],
      "properties": {
        "Hour": {
          "type": "integer",
          "format": "int64"
        },
        "LoadStation": {
          "type": "integer",
          "format": "int32"
        },
        "WaitForOper": {
          "type": "string",
          "format": "time-span"
        },
        "Use": {
          "type": "string",
          "format": "time-span"
        },
        "Insp": {
          "type": "string",
          "format": "time-span"
        },
        "Outbound": {
          "type": "string",
          "format": "time-span"
        }
      }
    },
    "SimulatedLabor": {
      "type": "object",
      "required": ["Hour", "TeamName", "Work"],
      "properties": {
        "Hour": {
          "type": "integer",
          "format": "int64"
        },
        "TeamName": {
          "type": "string"
        },
        "Work": {
          "type": "string",
          "format": "time-span"
        },
        "Insp": {
          "type": "string",
          "format": "time-span"
        }
      }
    },
    "SimulatedPallet": {
      "type": "object",
      "required": ["Hour", "Pallet"],
      "properties": {
        "Hour": {
          "type": "integer",
          "format": "int64"
        },
        "Pallet": {
          "type": "integer",
          "format": "int32"
        },
        "Moves": {
          "type": "integer",
          "format": "int32"
        },
        "BeforeMachine": {
          "type": "string",
          "format": "time-span"
        },
        "BeforeUnload": {
          "type": "string",
          "format": "time-span"
        },
        "Occupied": {
          "type": "string",
          "format": "time-span"
        }
      }
    },
    "SimulatedQueue": {
      "type": "object",
      "required": ["Hour", "Queue", "AvgSize", "MaxSize"],
      "properties": {
        "Hour": {
          "type": "integer",
          "format": "int64"
        },
        "Queue": {
          "type": "string"
        },
        "AvgSize": {
          "type": "number",
          "format": "double"
        },
        "MaxSize": {
          "type": "integer",
          "format": "int32"
        }
      }
    },
    "SimulatedInspectStand": {
      "type": "object",
      "required": ["Hour", "InspType", "Use"],
      "properties": {
        "Hour": {
          "type": "integer",
          "format": "int64"
        },
        "InspType": {
          "type": "string"
        },
        "Use": {
          "type": "string",
          "format": "time-span"
        },
        "WaitForOper": {
          "type": "string",
          "format": "time-span"
        }
      }
    },
    "AllocateDetails": {
      "allOf": [
        {
          "$ref": "/schemas/fms-insight#/components/schemas/SimulationResults"
        },
        {
          "type": "object",
          "properties": {
            "SimPartCompleted": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/SimulatedPartCompleted"
              }
            },
            "SimMachineUsage": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/SimulatedMachine"
              }
            },
            "SimLoadStationUsage": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/SimulatedLoadStation"
              }
            },
            "SimLaborUsage": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/SimulatedLabor"
              }
            },
            "SimPalletUsage": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/SimulatedPallet"
              }
            },
            "SimQueueUsage": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/SimulatedQueue"
              }
            },
            "SimInspectStands": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/SimulatedInspectStand"
              }
            }
          }
        }
      ]
    }
  }
}