{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/saturation-io/json-schema/saturation-io-purchase-order-schema.json",
  "title": "PurchaseOrder",
  "description": "A purchase order in Saturation.",
  "x-generated": "2026-11-23",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/saturation-io-openapi.yml#/components/schemas/PurchaseOrder",
  "type": "object",
  "required": [
    "id",
    "workspaceId",
    "projectId",
    "status",
    "currency",
    "exchangeRate",
    "exchangeRateSource",
    "amount",
    "createdAt",
    "updatedAt"
  ],
  "additionalProperties": false,
  "properties": {
    "id": {
      "$ref": "#/$defs/Id"
    },
    "workspaceId": {
      "$ref": "#/$defs/Id"
    },
    "projectId": {
      "description": "Assigned project ID, or `null` when unassigned.",
      "oneOf": [
        {
          "$ref": "#/$defs/Id"
        },
        {
          "type": "null"
        }
      ]
    },
    "number": {
      "type": [
        "string",
        "null"
      ],
      "description": "Purchase order number, such as `PO-0042`."
    },
    "name": {
      "type": [
        "string",
        "null"
      ],
      "description": "Purchase order name."
    },
    "status": {
      "$ref": "#/$defs/PurchaseOrderStatus"
    },
    "contactId": {
      "type": [
        "string",
        "null"
      ],
      "description": "Vendor contact ID."
    },
    "budgetLineId": {
      "type": [
        "string",
        "null"
      ],
      "description": "Budget line ID."
    },
    "dueDate": {
      "type": [
        "string",
        "null"
      ],
      "format": "date",
      "description": "Payment due date."
    },
    "serviceStartAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date",
      "description": "First service date."
    },
    "serviceEndAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date",
      "description": "Last service date."
    },
    "notes": {
      "type": [
        "string",
        "null"
      ],
      "description": "Notes about the purchase order."
    },
    "sort": {
      "type": [
        "number",
        "null"
      ],
      "description": "Display order within the project."
    },
    "currency": {
      "type": "string",
      "minLength": 3,
      "maxLength": 3,
      "description": "Purchase order currency."
    },
    "exchangeRate": {
      "type": [
        "number",
        "null"
      ],
      "description": "Rate from the purchase order currency to the workspace currency."
    },
    "exchangeRateSource": {
      "type": [
        "string",
        "null"
      ],
      "description": "Where the exchange rate came from."
    },
    "createdById": {
      "type": [
        "string",
        "null"
      ],
      "description": "ID of the user who created the purchase order."
    },
    "amount": {
      "allOf": [
        {
          "$ref": "#/$defs/Money"
        }
      ],
      "description": "Sum of item amounts in the purchase order currency."
    },
    "createdAt": {
      "type": "string",
      "format": "date-time",
      "description": "Time the purchase order was created."
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time",
      "description": "Time the purchase order was last updated."
    },
    "items": {
      "type": "array",
      "description": "Purchase order items. Included with `expand=items`.",
      "items": {
        "$ref": "#/$defs/PurchaseOrderItem"
      }
    },
    "contact": {
      "description": "Vendor contact. Included with `expand=contact`.",
      "oneOf": [
        {
          "$ref": "#/$defs/PurchaseOrderContactRef"
        },
        {
          "type": "null"
        }
      ]
    },
    "transactions": {
      "type": "array",
      "description": "Linked transactions. Included with `expand=transactions`.",
      "items": {
        "$ref": "#/$defs/PurchaseOrderTransactionRef"
      }
    },
    "documents": {
      "type": "array",
      "description": "Related documents. Included with `expand=documents`.",
      "items": {
        "$ref": "#/$defs/PurchaseOrderDocumentRef"
      }
    },
    "paymentRequests": {
      "type": "array",
      "description": "Related payment requests. Included with `expand=paymentRequests`.",
      "items": {
        "$ref": "#/$defs/PaymentRequestBase"
      }
    },
    "payments": {
      "type": "array",
      "description": "Related payments. Included with `expand=payments`.",
      "items": {
        "$ref": "#/$defs/PaymentBase"
      }
    },
    "budgetLine": {
      "description": "Budget line charged by the purchase order. Included with `expand=budgetLine`.",
      "oneOf": [
        {
          "$ref": "#/$defs/PurchaseOrderBudgetLineRef"
        },
        {
          "type": "null"
        }
      ]
    },
    "activity": {
      "description": "Current Activity column details. Included with `expand=activity`.",
      "oneOf": [
        {
          "$ref": "#/$defs/PurchaseOrderActivitySummary"
        },
        {
          "type": "null"
        }
      ]
    },
    "summary": {
      "description": "Purchase order totals. Included on detail responses or with `expand=summary`.",
      "oneOf": [
        {
          "$ref": "#/$defs/PurchaseOrderSummary"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "$defs": {
    "Id": {
      "type": "string",
      "description": "A stable resource ID, such as `prj_…`, `txn_…`, or `doc_…`."
    },
    "Money": {
      "type": "object",
      "description": "An amount in integer minor units and its ISO-4217 currency.",
      "required": [
        "amount",
        "currency"
      ],
      "additionalProperties": false,
      "properties": {
        "amount": {
          "type": "integer",
          "format": "int64",
          "minimum": -4503599627370496,
          "maximum": 4503599627370496,
          "description": "Amount in the currency's smallest unit, such as cents. May be negative, and at most 2^52 either way."
        },
        "currency": {
          "type": "string",
          "description": "ISO-4217 currency code.",
          "minLength": 3,
          "maxLength": 3,
          "pattern": "^[A-Za-z]{3}$"
        }
      }
    },
    "PaymentBase": {
      "type": "object",
      "description": "A payment and its current status.",
      "required": [
        "id",
        "workspaceId",
        "projectId",
        "paymentRequestId",
        "purchaseOrderId",
        "contactId",
        "budgetLineId",
        "status",
        "amount",
        "destinationAmount",
        "rail",
        "description",
        "memo",
        "notes",
        "scheduledFor",
        "expectedArrivalAt",
        "destination",
        "cancellationRequested",
        "needsSupport",
        "failureReason",
        "createdAt",
        "updatedAt"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "workspaceId": {
          "$ref": "#/$defs/Id"
        },
        "projectId": {
          "type": [
            "string",
            "null"
          ]
        },
        "paymentRequestId": {
          "type": [
            "string",
            "null"
          ]
        },
        "purchaseOrderId": {
          "type": [
            "string",
            "null"
          ]
        },
        "contactId": {
          "type": [
            "string",
            "null"
          ]
        },
        "budgetLineId": {
          "type": [
            "string",
            "null"
          ]
        },
        "status": {
          "$ref": "#/$defs/PaymentStatus"
        },
        "amount": {
          "$ref": "#/$defs/Money"
        },
        "destinationAmount": {
          "oneOf": [
            {
              "$ref": "#/$defs/Money"
            },
            {
              "type": "null"
            }
          ]
        },
        "rail": {
          "type": [
            "string",
            "null"
          ]
        },
        "description": {
          "type": [
            "string",
            "null"
          ]
        },
        "memo": {
          "type": [
            "string",
            "null"
          ]
        },
        "notes": {
          "type": [
            "string",
            "null"
          ]
        },
        "scheduledFor": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "expectedArrivalAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "destination": {
          "oneOf": [
            {
              "type": "object",
              "required": [
                "bankName",
                "accountType",
                "accountLast4",
                "network"
              ],
              "additionalProperties": false,
              "properties": {
                "bankName": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "accountType": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "accountLast4": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "network": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "cancellationRequested": {
          "type": "boolean"
        },
        "needsSupport": {
          "type": "boolean"
        },
        "failureReason": {
          "type": [
            "string",
            "null"
          ]
        },
        "createdAt": {
          "type": "string",
          "format": "date-time"
        },
        "updatedAt": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "PaymentRequestBase": {
      "type": "object",
      "description": "A request to pay a person or company.",
      "required": [
        "id",
        "workspaceId",
        "projectId",
        "purchaseOrderId",
        "contactId",
        "budgetLineId",
        "amount",
        "description",
        "memo",
        "dueDate",
        "method",
        "status",
        "submittedAt",
        "approvedAt",
        "rejectedAt",
        "completedAt",
        "createdAt",
        "updatedAt"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "workspaceId": {
          "$ref": "#/$defs/Id"
        },
        "projectId": {
          "type": [
            "string",
            "null"
          ]
        },
        "purchaseOrderId": {
          "type": [
            "string",
            "null"
          ]
        },
        "contactId": {
          "type": [
            "string",
            "null"
          ]
        },
        "budgetLineId": {
          "type": [
            "string",
            "null"
          ]
        },
        "amount": {
          "$ref": "#/$defs/Money"
        },
        "description": {
          "type": [
            "string",
            "null"
          ]
        },
        "memo": {
          "type": [
            "string",
            "null"
          ]
        },
        "dueDate": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "method": {
          "type": [
            "string",
            "null"
          ]
        },
        "status": {
          "$ref": "#/$defs/PaymentRequestStatus"
        },
        "submittedAt": {
          "type": "string",
          "format": "date-time"
        },
        "approvedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "rejectedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "completedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "createdAt": {
          "type": "string",
          "format": "date-time"
        },
        "updatedAt": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "PaymentRequestStatus": {
      "type": "string",
      "description": "Current payment-request status. `unknown` means the status is unavailable.",
      "enum": [
        "submitted",
        "pending",
        "approved",
        "paid",
        "rejected",
        "canceled",
        "unknown"
      ]
    },
    "PaymentStatus": {
      "type": "string",
      "description": "Current payment status.",
      "enum": [
        "requested",
        "needs_approval",
        "ready_to_pay",
        "scheduled",
        "sending",
        "settled",
        "returned",
        "failed",
        "rejected",
        "canceled"
      ]
    },
    "PurchaseOrderActivityItem": {
      "type": "object",
      "description": "One entry in the purchase order Activity column.",
      "required": [
        "type",
        "label",
        "severity",
        "count",
        "sourceIds"
      ],
      "additionalProperties": false,
      "properties": {
        "type": {
          "$ref": "#/$defs/PurchaseOrderActivityType"
        },
        "label": {
          "type": "string"
        },
        "severity": {
          "$ref": "#/$defs/PurchaseOrderActivitySeverity"
        },
        "count": {
          "type": "integer",
          "minimum": 0
        },
        "sourceIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "PurchaseOrderActivitySeverity": {
      "type": "string",
      "enum": [
        "neutral",
        "info",
        "warning",
        "danger",
        "success"
      ]
    },
    "PurchaseOrderActivitySummary": {
      "type": "object",
      "description": "Current purchase order activity.",
      "required": [
        "primaryActivity",
        "items"
      ],
      "additionalProperties": false,
      "properties": {
        "primaryActivity": {
          "oneOf": [
            {
              "$ref": "#/$defs/PurchaseOrderActivityItem"
            },
            {
              "type": "null"
            }
          ]
        },
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/PurchaseOrderActivityItem"
          }
        }
      }
    },
    "PurchaseOrderActivityType": {
      "type": "string",
      "description": "Activity shown in the purchase order Activity column.",
      "enum": [
        "invoice_requested",
        "invoice_received",
        "invoice_rejected",
        "payment_requested",
        "payment_approval_pending",
        "payment_approved",
        "payment_processing",
        "payment_sent",
        "payment_failed",
        "payment_returned",
        "actualized_needs_review",
        "split_needs_review",
        "transaction_match_needs_review"
      ]
    },
    "PurchaseOrderBudgetLineRef": {
      "type": "object",
      "description": "Budget line details included with a purchase order.",
      "required": [
        "id",
        "accountId",
        "type",
        "description",
        "parentId",
        "sort",
        "contactId",
        "lineColor",
        "emoji",
        "notes"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "accountId": {
          "type": [
            "string",
            "null"
          ]
        },
        "type": {
          "type": "string"
        },
        "description": {
          "type": [
            "string",
            "null"
          ]
        },
        "parentId": {
          "oneOf": [
            {
              "$ref": "#/$defs/Id"
            },
            {
              "type": "null"
            }
          ]
        },
        "sort": {
          "type": [
            "string",
            "null"
          ]
        },
        "contactId": {
          "oneOf": [
            {
              "$ref": "#/$defs/Id"
            },
            {
              "type": "null"
            }
          ]
        },
        "lineColor": {
          "type": [
            "string",
            "null"
          ]
        },
        "emoji": {
          "type": [
            "string",
            "null"
          ]
        },
        "notes": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "PurchaseOrderContactRef": {
      "type": "object",
      "description": "Vendor details included with a purchase order.",
      "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"
          ]
        }
      }
    },
    "PurchaseOrderDocumentRef": {
      "type": "object",
      "description": "Document details included with a purchase order.",
      "required": [
        "id",
        "name",
        "mimeType",
        "status",
        "size",
        "classification"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "name": {
          "type": "string"
        },
        "mimeType": {
          "type": "string"
        },
        "status": {
          "type": "string"
        },
        "size": {
          "type": "integer",
          "format": "int64"
        },
        "classification": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "PurchaseOrderItem": {
      "type": "object",
      "description": "An item in a purchase order.",
      "required": [
        "id",
        "purchaseOrderId",
        "sort"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "purchaseOrderId": {
          "$ref": "#/$defs/Id"
        },
        "lineNumber": {
          "type": [
            "string",
            "null"
          ],
          "description": "Line number shown in the itemization."
        },
        "description": {
          "type": [
            "string",
            "null"
          ],
          "description": "Item description."
        },
        "budgetLineId": {
          "type": [
            "string",
            "null"
          ],
          "description": "Budget line ID."
        },
        "qty": {
          "type": [
            "string",
            "null"
          ],
          "description": "Quantity or formula."
        },
        "unit": {
          "type": [
            "string",
            "null"
          ],
          "description": "Unit, such as `day`, `week`, or `each`."
        },
        "rate": {
          "type": [
            "string",
            "null"
          ],
          "description": "Rate or formula."
        },
        "amount": {
          "type": [
            "integer",
            "null"
          ],
          "format": "int64",
          "description": "Item total in minor currency units."
        },
        "sort": {
          "type": "string",
          "description": "Display order within the purchase order."
        }
      }
    },
    "PurchaseOrderStatus": {
      "type": "string",
      "description": "Current purchase order status.",
      "enum": [
        "draft",
        "pending",
        "approved",
        "rejected",
        "actualizing",
        "paid",
        "void"
      ]
    },
    "PurchaseOrderSummary": {
      "type": "object",
      "description": "Purchase order totals in its currency.",
      "required": [
        "purchaseOrderId",
        "currency",
        "amounts"
      ],
      "additionalProperties": false,
      "properties": {
        "purchaseOrderId": {
          "$ref": "#/$defs/Id"
        },
        "currency": {
          "type": "string",
          "minLength": 3,
          "maxLength": 3
        },
        "amounts": {
          "type": "object",
          "required": [
            "ordered",
            "requested",
            "invoiced",
            "sent",
            "actualized",
            "remaining",
            "variance"
          ],
          "additionalProperties": false,
          "properties": {
            "ordered": {
              "$ref": "#/$defs/Money"
            },
            "requested": {
              "$ref": "#/$defs/Money"
            },
            "invoiced": {
              "$ref": "#/$defs/Money"
            },
            "sent": {
              "$ref": "#/$defs/Money"
            },
            "actualized": {
              "$ref": "#/$defs/Money"
            },
            "remaining": {
              "$ref": "#/$defs/Money"
            },
            "variance": {
              "$ref": "#/$defs/Money"
            }
          }
        }
      }
    },
    "PurchaseOrderTransactionRef": {
      "type": "object",
      "description": "Transaction details included with a purchase order.",
      "required": [
        "id",
        "projectId",
        "purchaseOrderId",
        "amount",
        "description",
        "timestamp",
        "status",
        "type",
        "contactId",
        "budgetLineId"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "projectId": {
          "oneOf": [
            {
              "$ref": "#/$defs/Id"
            },
            {
              "type": "null"
            }
          ]
        },
        "purchaseOrderId": {
          "$ref": "#/$defs/Id"
        },
        "amount": {
          "type": [
            "integer",
            "null"
          ],
          "format": "int64"
        },
        "description": {
          "type": [
            "string",
            "null"
          ]
        },
        "timestamp": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "status": {
          "type": "string"
        },
        "type": {
          "type": [
            "string",
            "null"
          ]
        },
        "contactId": {
          "oneOf": [
            {
              "$ref": "#/$defs/Id"
            },
            {
              "type": "null"
            }
          ]
        },
        "budgetLineId": {
          "oneOf": [
            {
              "$ref": "#/$defs/Id"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    }
  }
}