{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/benjipays-com/json-schema/benjipays-com-get-invoice-response-schema.json",
  "title": "GetInvoiceResponse",
  "description": "Single invoice response (summary DTO; optional nested accounting when include=accounting)",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/benjipays-com-invoices-api-openapi.yml#/components/schemas/GetInvoiceResponse",
  "type": "object",
  "properties": {
    "data": {
      "$ref": "#/$defs/InvoiceSummary"
    }
  },
  "required": [
    "data"
  ],
  "additionalProperties": false,
  "$defs": {
    "InvoiceBrandingTheme": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "id": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "name": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "id",
            "name"
          ],
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ],
      "description": "Xero branding theme (id + name). Null for non-Xero systems."
    },
    "InvoiceCustomer": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "id": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "name": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "Customer display name from the accounting system"
            },
            "active": {
              "type": "boolean"
            },
            "isProject": {
              "description": "QBO-only (Jobs/sub-customers); omitted entirely for QBD, Xero, and Business Central.",
              "type": "boolean"
            },
            "parents": {
              "description": "Sub-customer/job hierarchy, direct parent first. QBO/QBD only; omitted entirely for Xero/Business Central.",
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "name": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "required": [
                  "id"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "id",
            "name",
            "active"
          ],
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ],
      "description": "Customer enrichment (from BenjiCustomer), camelCase, no internal Mongo fields."
    },
    "InvoiceSummary": {
      "type": "object",
      "properties": {
        "id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "Accounting system invoice ID (same value accepted by GET /invoices/:invoiceId)"
        },
        "invoiceNumber": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "Human-readable invoice number (filter: invoiceNumber)"
        },
        "invoiceDate": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "Invoice date YYYY-MM-DD (filter: invoiceDateStart/End)"
        },
        "dueDate": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "Due date YYYY-MM-DD (filter: dueDateStart/End)"
        },
        "postingDate": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "Business Central posting date YYYY-MM-DD. Null for other accounting systems and when no valid date is stored. A future date means the invoice cannot be charged until that date."
        },
        "createdDate": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "Created / approved timestamp when available (MetaData.CreateTime or bpApprovedDate)"
        },
        "total": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "description": "Invoice total (currency-sensible, 2dp)"
        },
        "balance": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "description": "Amount remaining (currency-sensible, 2dp)"
        },
        "subtotal": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ]
        },
        "taxTotal": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ]
        },
        "currency": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "ISO 4217 currency code"
        },
        "status": {
          "type": "string",
          "enum": [
            "open",
            "paid",
            "overdue"
          ],
          "description": "Per-invoice Benji status derived from balance / due date: `overdue` when unpaid past due, `open` when unpaid and not yet due, `paid` when balance is zero. Note the list `?status=open` filter returns all unpaid invoices regardless of due date, so it can include invoices whose own `status` here reads `overdue`; use `?status=overdue` to filter to only those. Native accounting status (Xero/BC) is only under `accounting` when include=accounting."
        },
        "paid": {
          "type": "boolean"
        },
        "emailed": {
          "type": "boolean"
        },
        "terms": {
          "$ref": "#/$defs/InvoiceTerms"
        },
        "brandingTheme": {
          "$ref": "#/$defs/InvoiceBrandingTheme"
        },
        "reference": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "memo": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "lastModifiedDate": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "customer": {
          "$ref": "#/$defs/InvoiceCustomer"
        },
        "accounting": {
          "description": "Full stored invoice object (fields from the accounting system plus our own). Only present on GET /invoices/:invoiceId when include=accounting.",
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {}
        }
      },
      "required": [
        "id",
        "invoiceNumber",
        "invoiceDate",
        "dueDate",
        "postingDate",
        "createdDate",
        "total",
        "balance",
        "subtotal",
        "taxTotal",
        "currency",
        "status",
        "paid",
        "emailed",
        "terms",
        "brandingTheme",
        "reference",
        "memo",
        "lastModifiedDate",
        "customer"
      ],
      "additionalProperties": false,
      "description": "Benji-controlled camelCase invoice summary. Top-level = stable API; optional `accounting` = full stored invoice (accounting-system fields plus our own; detail + include=accounting only)."
    },
    "InvoiceTerms": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "id": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "name": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "id",
            "name"
          ],
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ],
      "description": "Payment terms (id + name). Null for systems that do not use terms (e.g. Xero — use brandingTheme)."
    }
  }
}