{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/arcnm-io/json-schema/arcnm-io-nest-layout-check-schema.json",
  "title": "NestLayoutCheck",
  "description": "What the shop's cutter would find in the posted layout.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/arcnm-io-nesting-api-openapi.yml#/components/schemas/NestLayoutCheck",
  "properties": {
    "ok": {
      "type": "boolean",
      "title": "Ok",
      "description": "Every sheet can be cut, every copy keeps the environment's shop practice, and no remnant is over-used: what `POST …/revisions` accepts. A line short of its quantity or over it does not make a layout unacceptable — `missing` and `extra` state it, and a revision is priced on the copies it cuts."
    },
    "complete": {
      "type": "boolean",
      "title": "Complete",
      "description": "Every line is placed exactly as often as its quantity: `missing` and `extra` are empty."
    },
    "sheets": {
      "items": {
        "$ref": "#/$defs/NestSheetCheck"
      },
      "type": "array",
      "title": "Sheets"
    },
    "sheets_total": {
      "type": "integer",
      "title": "Sheets Total",
      "description": "Sheets, every one as often as it repeats."
    },
    "lines": {
      "items": {
        "$ref": "#/$defs/NestLineCount"
      },
      "type": "array",
      "title": "Lines"
    },
    "missing": {
      "items": {
        "$ref": "#/$defs/NestLineCount"
      },
      "type": "array",
      "title": "Missing",
      "description": "Lines with fewer copies placed than demanded (`placed` = the shortfall)."
    },
    "extra": {
      "items": {
        "$ref": "#/$defs/NestLineCount"
      },
      "type": "array",
      "title": "Extra",
      "description": "Lines with more copies placed than demanded (`placed` = the surplus)."
    },
    "containers_unknown": {
      "items": {
        "type": "string"
      },
      "type": "array",
      "title": "Containers Unknown"
    },
    "remnants_over": {
      "items": {
        "$ref": "#/$defs/NestRemnantOver"
      },
      "type": "array",
      "title": "Remnants Over"
    },
    "utilisation_net": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ],
      "title": "Utilisation Net",
      "description": "The parts' area over the sheet area used, reusable rests not counted."
    }
  },
  "type": "object",
  "required": [
    "ok",
    "complete",
    "sheets",
    "sheets_total",
    "lines",
    "missing",
    "extra",
    "containers_unknown",
    "remnants_over",
    "utilisation_net"
  ],
  "$defs": {
    "NestClash": {
      "properties": {
        "a": {
          "type": "integer",
          "title": "A",
          "description": "A placement's index on the sheet."
        },
        "b": {
          "type": "integer",
          "title": "B",
          "description": "The other's."
        },
        "gap_mm": {
          "type": "number",
          "title": "Gap Mm",
          "description": "How far apart they lie; 0 where they overlap. Less than the spacing."
        }
      },
      "type": "object",
      "required": [
        "a",
        "b",
        "gap_mm"
      ],
      "title": "NestClash"
    },
    "NestLineCount": {
      "properties": {
        "line_id": {
          "type": "string",
          "format": "uuid",
          "title": "Line Id"
        },
        "quantity": {
          "type": "integer",
          "title": "Quantity",
          "description": "Copies demanded."
        },
        "placed": {
          "type": "integer",
          "title": "Placed",
          "description": "Copies on the posted sheets."
        }
      },
      "type": "object",
      "required": [
        "line_id",
        "quantity",
        "placed"
      ],
      "title": "NestLineCount"
    },
    "NestPracticeBreach": {
      "properties": {
        "placement": {
          "type": "integer",
          "title": "Placement",
          "description": "The placement's index on the sheet."
        },
        "reason": {
          "type": "string",
          "enum": [
            "grain_direction",
            "mirroring"
          ],
          "title": "Reason",
          "description": "`grain_direction`: turned so the part's grain no longer runs the way the environment's grain direction states — `allowed_rot_deg` names the turns that keep it; `mirroring`: mirrored, and the environment allows no mirroring. Both are shop-practice answers (`PUT /environments/{env_id}/shop-practice`), read when the job nest ran."
        },
        "allowed_rot_deg": {
          "anyOf": [
            {
              "items": {
                "type": "number"
              },
              "type": "array"
            },
            {
              "type": "null"
            }
          ],
          "title": "Allowed Rot Deg",
          "description": "For `grain_direction`: the turns a copy may take, degrees."
        }
      },
      "type": "object",
      "required": [
        "placement",
        "reason"
      ],
      "title": "NestPracticeBreach",
      "description": "A copy the environment's shop practice does not allow."
    },
    "NestRemnantOver": {
      "properties": {
        "container_id": {
          "type": "string",
          "title": "Container Id"
        },
        "pieces": {
          "type": "integer",
          "title": "Pieces",
          "description": "Pieces the layout cuts from it."
        },
        "available": {
          "type": "integer",
          "title": "Available",
          "description": "Pieces the job nest had on offer."
        }
      },
      "type": "object",
      "required": [
        "container_id",
        "pieces",
        "available"
      ],
      "title": "NestRemnantOver"
    },
    "NestRest": {
      "properties": {
        "x_mm": {
          "type": "number",
          "title": "X Mm"
        },
        "y_mm": {
          "type": "number",
          "title": "Y Mm"
        },
        "length_mm": {
          "type": "number",
          "title": "Length Mm"
        },
        "width_mm": {
          "type": "number",
          "title": "Width Mm"
        },
        "reusable": {
          "type": "boolean",
          "title": "Reusable",
          "description": "Whether it clears the environment's remnant threshold and goes back to stock."
        }
      },
      "type": "object",
      "required": [
        "x_mm",
        "y_mm",
        "length_mm",
        "width_mm",
        "reusable"
      ],
      "title": "NestRest"
    },
    "NestSheetCheck": {
      "properties": {
        "index": {
          "type": "integer",
          "title": "Index"
        },
        "container_id": {
          "type": "string",
          "title": "Container Id"
        },
        "container_kind": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Container Kind",
          "description": "`format` or `remnant`; null when the job nest cannot cut from it."
        },
        "length_mm": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "title": "Length Mm"
        },
        "width_mm": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "title": "Width Mm"
        },
        "repeat": {
          "type": "integer",
          "title": "Repeat"
        },
        "count": {
          "type": "integer",
          "title": "Count",
          "description": "Placements on it."
        },
        "ok": {
          "type": "boolean",
          "title": "Ok"
        },
        "clashes_total": {
          "type": "integer",
          "title": "Clashes Total",
          "description": "Pairs closer than the spacing (or overlapping), all of them."
        },
        "clashes": {
          "items": {
            "$ref": "#/$defs/NestClash"
          },
          "type": "array",
          "title": "Clashes",
          "description": "Pairs closer than the spacing (or overlapping): the first 100 of `clashes_total`."
        },
        "outside": {
          "items": {
            "type": "integer"
          },
          "type": "array",
          "title": "Outside",
          "description": "Placements reaching into the margin or off the sheet."
        },
        "unknown_lines": {
          "items": {
            "type": "string",
            "format": "uuid"
          },
          "type": "array",
          "title": "Unknown Lines",
          "description": "Line ids that are not of this material and thickness."
        },
        "container_unknown": {
          "type": "boolean",
          "title": "Container Unknown"
        },
        "net_area_mm2": {
          "type": "number",
          "title": "Net Area Mm2"
        },
        "utilisation": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "title": "Utilisation",
          "description": "The parts' area over the sheet's."
        },
        "rest": {
          "anyOf": [
            {
              "$ref": "#/$defs/NestRest"
            },
            {
              "type": "null"
            }
          ],
          "description": "The largest rest the sheet leaves."
        },
        "against_shop_practice": {
          "items": {
            "$ref": "#/$defs/NestPracticeBreach"
          },
          "type": "array",
          "title": "Against Shop Practice",
          "description": "Placements the environment's shop practice does not allow: turned against its grain direction, or mirrored where it allows no mirroring. One entry per rule a placement breaks."
        }
      },
      "type": "object",
      "required": [
        "index",
        "container_id",
        "container_kind",
        "length_mm",
        "width_mm",
        "repeat",
        "count",
        "ok",
        "clashes_total",
        "clashes",
        "outside",
        "unknown_lines",
        "container_unknown",
        "net_area_mm2",
        "utilisation",
        "rest"
      ],
      "title": "NestSheetCheck",
      "description": "One posted sheet, checked."
    }
  }
}