{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/aginera-ai/json-schema/aginera-ai-takeoff-schema.json",
  "title": "Takeoff",
  "x-generated": "2026-11-01",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/aginera-ai-openapi.json#/components/schemas/Takeoff",
  "type": "object",
  "properties": {
    "id": {
      "$ref": "#/$defs/TakeoffId"
    },
    "document_id": {
      "$ref": "#/$defs/DocumentId"
    },
    "project_id": {
      "$ref": "#/$defs/ProjectId"
    },
    "discipline": {
      "$ref": "#/$defs/Discipline"
    },
    "status": {
      "$ref": "#/$defs/JobStatus"
    },
    "external_ref": {
      "type": [
        "string",
        "null"
      ]
    },
    "progress": {
      "$ref": "#/$defs/Progress"
    },
    "queue_position": {
      "type": "integer"
    },
    "origin": {
      "type": "string",
      "enum": [
        "api",
        "web_app"
      ],
      "description": "api = started through the API or an agent; web_app = a completed extraction run in the Aginera web app (read-only here; credits were billed by the app, so estimated_credits and credits_charged are 0)."
    },
    "pages_requested": {
      "type": "integer"
    },
    "estimated_credits": {
      "type": "number",
      "description": "Maximum that will be charged; the final charge never exceeds it."
    },
    "result_summary": {
      "type": "object",
      "properties": {
        "item_count": {
          "type": "integer"
        },
        "sheet_count": {
          "type": "integer"
        },
        "pages_processed": {
          "type": "integer"
        },
        "credits_charged": {
          "type": "number"
        },
        "route_count": {
          "type": "integer"
        },
        "schedule_count": {
          "type": "integer"
        },
        "by_trade": {
          "type": "object",
          "additionalProperties": {
            "type": "integer"
          }
        }
      },
      "required": [
        "item_count",
        "sheet_count",
        "credits_charged"
      ]
    },
    "warnings": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Warning"
      }
    },
    "failure": {
      "$ref": "#/$defs/Failure"
    },
    "metadata": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "started_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "completed_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    }
  },
  "required": [
    "id",
    "document_id",
    "project_id",
    "discipline",
    "status",
    "external_ref",
    "progress",
    "pages_requested",
    "estimated_credits",
    "warnings",
    "metadata",
    "created_at",
    "started_at",
    "completed_at"
  ],
  "$defs": {
    "Discipline": {
      "type": "string",
      "enum": [
        "electrical",
        "mechanical",
        "plumbing",
        "fire_protection",
        "process",
        "structural",
        "multi_discipline"
      ]
    },
    "DocumentId": {
      "type": "string",
      "pattern": "^doc_[0-9A-Za-z]{22}$"
    },
    "Failure": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string",
          "enum": [
            "document_unreadable",
            "unsupported_content",
            "no_pages_selected",
            "capacity",
            "cancelled",
            "internal"
          ]
        },
        "message": {
          "type": "string"
        }
      },
      "required": [
        "code",
        "message"
      ]
    },
    "JobStatus": {
      "type": "string",
      "enum": [
        "queued",
        "processing",
        "completed",
        "failed",
        "cancelled"
      ]
    },
    "Progress": {
      "type": "object",
      "properties": {
        "percent": {
          "type": "integer",
          "minimum": 0,
          "maximum": 100
        },
        "pages_processed": {
          "type": "integer"
        },
        "pages_total": {
          "type": "integer"
        }
      },
      "required": [
        "percent"
      ]
    },
    "ProjectId": {
      "type": "string",
      "pattern": "^prj_[0-9A-Za-z]{22}$"
    },
    "TakeoffId": {
      "type": "string",
      "pattern": "^tko_[0-9A-Za-z]{22}$"
    },
    "Warning": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string",
          "enum": [
            "discipline_mismatch",
            "scanned_pages_low_quality",
            "pages_skipped_no_content",
            "no_items_found",
            "partial_pages_failed",
            "duplicate_document",
            "pages_not_read",
            "free_plan_sheets"
          ]
        },
        "message": {
          "type": "string"
        },
        "pages": {
          "type": "array",
          "items": {
            "type": "integer"
          }
        }
      },
      "required": [
        "code",
        "message"
      ]
    }
  }
}