{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://abcs.sirvisetti.com/schemas/objects/procurement/purchase-order.schema.json",
  "title": "ABCS Procurement Purchase Order",
  "type": "object",
  "additionalProperties": false,
  "required": ["number", "buyer", "supplier", "orderDate", "currency", "lines", "status"],
  "properties": {
    "number": {"type": "string", "minLength": 1},
    "revision": {"type": "string"},
    "orderDate": {"type": "string", "format": "date"},
    "buyer": {"$ref": "https://abcs.sirvisetti.com/schemas/common/party-reference.schema.json"},
    "supplier": {"$ref": "https://abcs.sirvisetti.com/schemas/common/party-reference.schema.json"},
    "supplierSite": {"type": "string"},
    "currency": {"type": "string", "pattern": "^[A-Z]{3}$"},
    "paymentTerms": {"type": "string"},
    "shipTo": {"$ref": "https://abcs.sirvisetti.com/schemas/common/address.schema.json"},
    "billTo": {"$ref": "https://abcs.sirvisetti.com/schemas/common/address.schema.json"},
    "requisitions": {"type": "array", "items": {"$ref": "https://abcs.sirvisetti.com/schemas/common/business-object-reference.schema.json"}},
    "lines": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/line"}},
    "amounts": {"$ref": "#/$defs/amounts"},
    "status": {"$ref": "#/$defs/status"},
    "createdAt": {"type": "string", "format": "date-time"},
    "updatedAt": {"type": "string", "format": "date-time"}
  },
  "$defs": {
    "line": {
      "type": "object",
      "additionalProperties": false,
      "required": ["lineNumber", "quantity"],
      "properties": {
        "lineNumber": {"type": "integer", "minimum": 1},
        "item": {"type": "object", "additionalProperties": false, "properties": {"identifier": {"type": "string"}, "description": {"type": "string"}}},
        "description": {"type": "string"},
        "quantity": {"$ref": "https://abcs.sirvisetti.com/schemas/common/quantity.schema.json"},
        "unitPrice": {"$ref": "https://abcs.sirvisetti.com/schemas/common/monetary-amount.schema.json"},
        "amount": {"$ref": "https://abcs.sirvisetti.com/schemas/common/monetary-amount.schema.json"},
        "requestedDeliveryDate": {"type": "string", "format": "date"},
        "shipTo": {"$ref": "https://abcs.sirvisetti.com/schemas/common/address.schema.json"}
      }
    },
    "amounts": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "subtotal": {"$ref": "https://abcs.sirvisetti.com/schemas/common/monetary-amount.schema.json"},
        "tax": {"$ref": "https://abcs.sirvisetti.com/schemas/common/monetary-amount.schema.json"},
        "total": {"$ref": "https://abcs.sirvisetti.com/schemas/common/monetary-amount.schema.json"}
      }
    },
    "status": {
      "type": "object",
      "additionalProperties": false,
      "required": ["lifecycle", "approval", "fulfillment", "invoicing"],
      "properties": {
        "lifecycle": {"type": "string", "enum": ["draft", "open", "closed", "cancelled"]},
        "approval": {"type": "string", "enum": ["not-required", "not-submitted", "pending", "approved", "rejected"]},
        "fulfillment": {"type": "string", "enum": ["not-received", "partially-received", "received"]},
        "invoicing": {"type": "string", "enum": ["not-invoiced", "partially-invoiced", "invoiced"]}
      }
    }
  }
}
