{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/buildworkpro-com/json-schema/buildworkpro-com-invoice-billing-source-result-schema.json",
  "title": "InvoiceBillingSourceResult",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/buildworkpro-com-invoices-api-openapi.yml#/components/schemas/InvoiceBillingSourceResult",
  "type": "object",
  "properties": {
    "invoice": {
      "$ref": "#/$defs/Invoice"
    },
    "before": {
      "type": "object",
      "properties": {
        "sourcePayAppId": {
          "type": [
            "integer",
            "null"
          ]
        },
        "paymentTermInstallmentId": {
          "type": [
            "integer",
            "null"
          ]
        },
        "sourceBidId": {
          "type": [
            "integer",
            "null"
          ]
        },
        "sourceType": {
          "type": "string",
          "enum": [
            "bid",
            "pay_app",
            "ad_hoc"
          ]
        }
      },
      "required": [
        "sourcePayAppId",
        "paymentTermInstallmentId",
        "sourceBidId",
        "sourceType"
      ]
    },
    "after": {
      "type": "object",
      "properties": {
        "sourcePayAppId": {
          "type": [
            "integer",
            "null"
          ]
        },
        "paymentTermInstallmentId": {
          "type": [
            "integer",
            "null"
          ]
        },
        "sourceBidId": {
          "type": [
            "integer",
            "null"
          ]
        },
        "sourceType": {
          "type": "string",
          "enum": [
            "bid",
            "pay_app",
            "ad_hoc"
          ]
        }
      },
      "required": [
        "sourcePayAppId",
        "paymentTermInstallmentId",
        "sourceBidId",
        "sourceType"
      ]
    },
    "changed": {
      "type": "boolean"
    },
    "dryRun": {
      "type": "boolean"
    },
    "billing": {
      "type": "object",
      "properties": {
        "before": {
          "$ref": "#/$defs/ProjectBillingFigures"
        },
        "after": {
          "$ref": "#/$defs/ProjectBillingFigures"
        }
      },
      "required": [
        "before",
        "after"
      ]
    }
  },
  "required": [
    "invoice",
    "before",
    "after",
    "changed",
    "dryRun",
    "billing"
  ],
  "$defs": {
    "Invoice": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer"
        },
        "tenantId": {
          "type": "integer"
        },
        "invoiceNumber": {
          "type": "string"
        },
        "projectId": {
          "type": [
            "integer",
            "null"
          ]
        },
        "contactId": {
          "type": [
            "integer",
            "null"
          ]
        },
        "status": {
          "type": "string",
          "enum": [
            "draft",
            "sent",
            "partial",
            "paid",
            "voided"
          ]
        },
        "issueDate": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "dueDate": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "subtotal": {
          "type": "string"
        },
        "taxAmount": {
          "type": "string"
        },
        "total": {
          "type": "string"
        },
        "amountPaid": {
          "type": "string"
        },
        "balanceDue": {
          "type": "string"
        },
        "notesToCustomer": {
          "type": [
            "string",
            "null"
          ]
        },
        "createdAt": {
          "type": "string",
          "format": "date-time"
        },
        "updatedAt": {
          "type": "string",
          "format": "date-time"
        }
      },
      "required": [
        "id",
        "tenantId",
        "invoiceNumber",
        "projectId",
        "contactId",
        "status",
        "issueDate",
        "dueDate",
        "subtotal",
        "taxAmount",
        "total",
        "amountPaid",
        "balanceDue",
        "notesToCustomer",
        "createdAt",
        "updatedAt"
      ]
    },
    "ProjectBillingFigures": {
      "type": "object",
      "properties": {
        "invoiced": {
          "type": "number"
        },
        "invoicedPreTax": {
          "type": "number"
        },
        "paid": {
          "type": "number"
        },
        "outstanding": {
          "type": "number"
        },
        "invoiceCount": {
          "type": "integer"
        },
        "payAppBilled": {
          "type": "number"
        },
        "billedTotal": {
          "type": "number"
        },
        "billedCash": {
          "type": "number"
        },
        "outstandingCash": {
          "type": "number"
        },
        "retainageHeld": {
          "type": "number"
        },
        "remaining": {
          "type": "number"
        },
        "hasBilling": {
          "type": "boolean"
        }
      },
      "required": [
        "invoiced",
        "invoicedPreTax",
        "paid",
        "outstanding",
        "invoiceCount",
        "payAppBilled",
        "billedTotal",
        "billedCash",
        "outstandingCash",
        "retainageHeld",
        "remaining",
        "hasBilling"
      ]
    }
  }
}