{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/saturation-io/json-schema/saturation-io-budget-line-schema.json",
  "title": "BudgetLine",
  "description": "A budget line. Related data appears when requested with `expand`.",
  "x-generated": "2026-11-23",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/saturation-io-openapi.yml#/components/schemas/BudgetLine",
  "type": "object",
  "required": [
    "id",
    "type",
    "description",
    "parentId",
    "sort"
  ],
  "additionalProperties": false,
  "properties": {
    "id": {
      "$ref": "#/$defs/Id"
    },
    "accountId": {
      "type": [
        "string",
        "null"
      ],
      "description": "The account code shown in the Acct column, such as `520` or `0520`. It does not need to be unique."
    },
    "path": {
      "type": [
        "string",
        "null"
      ],
      "description": "The account path, such as `1100/1110`."
    },
    "type": {
      "$ref": "#/$defs/BudgetLineType"
    },
    "description": {
      "type": "string",
      "description": "The line description."
    },
    "parentId": {
      "oneOf": [
        {
          "$ref": "#/$defs/Id"
        },
        {
          "type": "null"
        }
      ]
    },
    "depth": {
      "type": "integer",
      "description": "The line's depth in the account tree. Root accounts have depth 0."
    },
    "sort": {
      "type": "integer",
      "description": "The display order among lines with the same parent."
    },
    "contactId": {
      "oneOf": [
        {
          "$ref": "#/$defs/Id"
        },
        {
          "type": "null"
        }
      ]
    },
    "lineColor": {
      "type": [
        "string",
        "null"
      ],
      "description": "The line color."
    },
    "emoji": {
      "type": [
        "string",
        "null"
      ]
    },
    "notes": {
      "type": [
        "string",
        "null"
      ],
      "description": "A plain-text note on the line."
    },
    "tagIds": {
      "type": "array",
      "description": "The IDs of tags on this line, the deduped union of residual line-level tags and the tags on the line's estimate-phase cells.",
      "items": {
        "$ref": "#/$defs/Id"
      }
    },
    "subtotalSumAllAbove": {
      "type": "boolean",
      "description": "For a `subtotal` line, whether to include every preceding line."
    },
    "subtotalIsBold": {
      "type": "boolean"
    },
    "markupAccountFilter": {
      "type": [
        "string",
        "null"
      ],
      "description": "For a `markup` line, the accounts included in the markup."
    },
    "contact": {
      "description": "The contact. Included with `expand=contact`.",
      "oneOf": [
        {
          "$ref": "#/$defs/BudgetLineContactRef"
        },
        {
          "type": "null"
        }
      ]
    },
    "phaseTotals": {
      "type": "object",
      "description": "Totals keyed by phase ID. Included with `expand=phaseTotals`.",
      "additionalProperties": {
        "$ref": "#/$defs/PhaseValues"
      }
    },
    "phaseData": {
      "type": "object",
      "description": "Editable phase data keyed by phase ID. Included with `expand=phaseData`.",
      "additionalProperties": {
        "$ref": "#/$defs/BudgetDocumentLinePhaseData"
      }
    }
  },
  "$defs": {
    "BudgetDocumentLinePhaseData": {
      "type": "object",
      "description": "Editable data for one budget line and phase.",
      "required": [
        "rate",
        "quantity",
        "multiplier",
        "qtyAutoDerived",
        "unit",
        "customUnitId",
        "unitLabel",
        "startDate",
        "endDate",
        "fringeIds",
        "fringeGroupIds",
        "currencyId",
        "overtime"
      ],
      "additionalProperties": false,
      "properties": {
        "rate": {
          "$ref": "#/$defs/BudgetDocumentPhaseDataValue"
        },
        "quantity": {
          "$ref": "#/$defs/BudgetDocumentPhaseDataValue"
        },
        "multiplier": {
          "$ref": "#/$defs/BudgetDocumentPhaseDataValue"
        },
        "qtyAutoDerived": {
          "type": "boolean"
        },
        "unit": {
          "type": [
            "string",
            "null"
          ]
        },
        "customUnitId": {
          "oneOf": [
            {
              "$ref": "#/$defs/Id"
            },
            {
              "type": "null"
            }
          ]
        },
        "unitLabel": {
          "type": [
            "string",
            "null"
          ]
        },
        "startDate": {
          "type": [
            "string",
            "null"
          ]
        },
        "endDate": {
          "type": [
            "string",
            "null"
          ]
        },
        "fringeIds": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Id"
          }
        },
        "fringeGroupIds": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Id"
          }
        },
        "currencyId": {
          "oneOf": [
            {
              "$ref": "#/$defs/Id"
            },
            {
              "type": "null"
            }
          ]
        },
        "overtime": {
          "$ref": "#/$defs/BudgetDocumentOvertime"
        },
        "tagIds": {
          "type": "array",
          "description": "The IDs of tags set on this phase of the line. Present on every estimate phase, empty when the phase has no tags. Absent on markup lines, which cannot hold tags. Deleted tags are left out, and tags set on a parent account's phase are not repeated here.",
          "items": {
            "$ref": "#/$defs/Id"
          }
        },
        "markupType": {
          "type": "string",
          "description": "Stored markup type. Includes Percent, Flat, ReferencePhase, and Assigned. Present only for a stored markup phase row."
        },
        "markupAmount": {
          "type": [
            "number",
            "null"
          ],
          "description": "Stored percentage points for Percent (10 means 10%), or currency amount for Flat. Null means no amount is set. ReferencePhase and Assigned rows do not compute from this value."
        },
        "markupApplyOn": {
          "type": "string",
          "description": "Stored calculation basis. Base is base, Base + Fringes is combined, and Fringes is fringes. Some existing rows return another basis, which is readable but cannot be authored."
        },
        "cascadePriorMarkups": {
          "type": "boolean",
          "description": "Whether the markup includes prior markups in its calculation basis."
        },
        "referencePhaseId": {
          "type": [
            "string",
            "null"
          ],
          "description": "For a ReferencePhase row, the estimate phase it copies. Null means no phase is picked and the row adds zero. Read-only."
        },
        "referenceMode": {
          "type": "string",
          "description": "For a ReferencePhase row, amount copies the target phase's markup total and configuration copies its rate and settings. Read-only."
        }
      }
    },
    "BudgetDocumentOvertime": {
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "properties": {
        "mode": {
          "type": [
            "string",
            "null"
          ]
        },
        "flatAmount": {
          "type": [
            "number",
            "null"
          ]
        },
        "hours": {
          "type": [
            "number",
            "null"
          ]
        },
        "baseHours": {
          "type": [
            "number",
            "null"
          ]
        },
        "multipliers": {
          "description": "Overtime multipliers."
        },
        "detail": {
          "description": "Overtime details."
        }
      }
    },
    "BudgetDocumentPhaseDataValue": {
      "description": "A phase value. Formulas and variable references remain strings. A missing value is null.",
      "type": [
        "number",
        "string",
        "null"
      ]
    },
    "BudgetLineContactRef": {
      "type": "object",
      "description": "Contact details included with a budget line.",
      "required": [
        "id",
        "displayName",
        "name",
        "company",
        "email",
        "type"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "displayName": {
          "type": "string"
        },
        "name": {
          "type": [
            "string",
            "null"
          ]
        },
        "company": {
          "type": [
            "string",
            "null"
          ]
        },
        "email": {
          "type": [
            "string",
            "null"
          ]
        },
        "type": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "BudgetLineType": {
      "type": "string",
      "description": "The budget line type.",
      "enum": [
        "account",
        "line",
        "subtotal",
        "fringe",
        "markup",
        "credit",
        "banner"
      ]
    },
    "FringeBreakdownEntry": {
      "type": "object",
      "description": "One fringe included in a phase total.",
      "required": [
        "id",
        "name",
        "amount"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "name": {
          "type": "string",
          "description": "The fringe name."
        },
        "amount": {
          "type": "number",
          "description": "The fringe amount, a decimal in the major units of the phase's currency."
        }
      }
    },
    "Id": {
      "type": "string",
      "description": "A stable resource ID, such as `prj_…`, `txn_…`, or `doc_…`."
    },
    "PhaseValues": {
      "type": "object",
      "description": "Totals for one budget line and phase. Amounts are decimals in the major units of the phase's currency (`currency`), as the engine computes them (rate 100 at quantity 10 is 1000). `amount` and `combined` are equal.",
      "required": [
        "base",
        "overtime",
        "fringe",
        "fringeBreakdown",
        "amount",
        "combined",
        "currency"
      ],
      "additionalProperties": false,
      "properties": {
        "base": {
          "type": "number",
          "description": "The amount before overtime and fringes, in major units."
        },
        "overtime": {
          "type": "number",
          "description": "The overtime amount in major units."
        },
        "fringe": {
          "type": "number",
          "description": "The total fringe amount in major units."
        },
        "fringeBreakdown": {
          "type": "array",
          "description": "The fringes included in `fringe`.",
          "items": {
            "$ref": "#/$defs/FringeBreakdownEntry"
          }
        },
        "amount": {
          "type": "number",
          "description": "The total amount in major units."
        },
        "combined": {
          "type": "number",
          "description": "The total after overtime, fringes, and credits. Equal to `amount`."
        },
        "currency": {
          "type": "string",
          "description": "The phase's currency as an ISO 4217 code.",
          "minLength": 3,
          "maxLength": 3
        }
      }
    }
  }
}