{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://unvtd.unece.org/purchase-order-schema.json",
  "type": "object",
  "required": [
    "@context",
    "type",
    "issuer",
    "credentialSubject",
    "credentialSchema"
  ],
  "description": "A purchase order is a commercial document issued by a buyer to a seller, indicating types, quantities, and agreed prices for products or services.",
  "properties": {
    "@context": {
      "type": "array",
      "description": "JSON-LD contexts: the W3C Verifiable Credentials v2 context, followed by this document's context.",
      "const": [
        "https://www.w3.org/ns/credentials/v2",
        "https://unvtd.unece.org/purchase-order-context.jsonld"
      ]
    },
    "type": {
      "type": "array",
      "description": "Credential types.",
      "const": [
        "VerifiableCredential",
        "PurchaseOrderCredential"
      ]
    },
    "name": {
      "type": "string",
      "description": "Human-readable name of the credential, for display.",
      "example": "Purchase Order"
    },
    "credentialSchema": {
      "type": "object",
      "description": "Reference to the credential schema for validation",
      "properties": {
        "id": {
          "type": "string",
          "format": "uri",
          "const": "https://unvtd.unece.org/purchase-order-schema.json",
          "description": "Public location of the schema"
        },
        "type": {
          "type": "string",
          "const": "JsonSchema",
          "description": "Schema type identifier"
        }
      },
      "required": [
        "id",
        "type"
      ]
    },
    "id": {
      "type": "string",
      "format": "uri",
      "description": "Unique identifier for this purchase order credential",
      "example": "urn:uuid:e9bf65a3-9ff3-4988-8c44-2535b949279f"
    },
    "validFrom": {
      "example": "2025-03-06T10:00:00.000Z",
      "type": "string",
      "format": "date-time",
      "description": "Date from which this credential is valid"
    },
    "validUntil": {
      "example": "2026-03-06T10:00:00.000Z",
      "type": "string",
      "format": "date-time",
      "description": "Date until which this credential is valid."
    },
    "issuer": {
      "name": "Issuer",
      "description": "Identifier of the party that issued this purchase order credential (e.g., DID)",
      "type": "string",
      "format": "uri",
      "example": "did:web:waveridersupplies.example.com"
    },
    "credentialSubject": {
      "name": "Purchase Order",
      "description": "Purchase order document details",
      "type": "object",
      "required": [
        "type",
        "purchaseOrderNumber",
        "orderDate",
        "buyer",
        "seller",
        "deliveryLocation",
        "orderedItems"
      ],
      "properties": {
        "type": {
          "type": "string",
          "description": "Type of the business document.",
          "const": "PurchaseOrder"
        },
        "purchaseOrderNumber": {
          "example": "PO-2025-001",
          "type": "string",
          "description": "Identifier assigned by the buyer to an order."
        },
        "orderDate": {
          "example": "2025-03-06T00:00:00Z",
          "type": "string",
          "format": "date-time",
          "description": "Date of order."
        },
        "buyer": {
          "description": "Party to which merchandise or services are sold.",
          "type": "object",
          "required": [
            "type",
            "id",
            "name"
          ],
          "properties": {
            "type": {
              "type": "string",
              "default": "Party",
              "enum": [
                "Party"
              ]
            },
            "id": {
              "example": "did:web:waveridersupplies.example.com",
              "type": "string",
              "format": "uri",
              "description": "A unique party identifier."
            },
            "name": {
              "example": "Wave Rider Supplies, Inc",
              "type": "string",
              "description": "Trade party name."
            },
            "postalAddress": {
              "description": "The postal address of the party.",
              "type": "object",
              "properties": {
                "type": {
                  "type": "string",
                  "default": "Address",
                  "enum": [
                    "Address"
                  ]
                },
                "streetAddress": {
                  "example": "210 Ocean Road",
                  "type": "string",
                  "description": "The street component of the address"
                },
                "addressLocality": {
                  "example": "Williamsburg",
                  "type": "string",
                  "description": "The city component of the address"
                },
                "addressRegion": {
                  "example": "NSW",
                  "type": "string",
                  "description": "The state component of the address"
                },
                "postalCode": {
                  "example": "75002",
                  "type": "string",
                  "description": "The postal code"
                },
                "addressCountry": {
                  "example": "AU",
                  "type": "string",
                  "description": "Country."
                }
              }
            }
          }
        },
        "seller": {
          "description": "Party selling merchandise or services to a buyer.",
          "type": "object",
          "required": [
            "type",
            "id",
            "name"
          ],
          "properties": {
            "type": {
              "type": "string",
              "default": "Party",
              "enum": [
                "Party"
              ]
            },
            "id": {
              "example": "did:web:surfpro.example.com",
              "type": "string",
              "format": "uri",
              "description": "A unique party identifier."
            },
            "name": {
              "example": "SurfPro Manufacturing Inc.",
              "type": "string",
              "description": "Trade party name."
            },
            "postalAddress": {
              "description": "The postal address of the party.",
              "type": "object",
              "properties": {
                "type": {
                  "type": "string",
                  "default": "Address",
                  "enum": [
                    "Address"
                  ]
                },
                "streetAddress": {
                  "example": "150 Industrial Drive",
                  "type": "string",
                  "description": "The street component of the address"
                },
                "addressLocality": {
                  "example": "Gold Coast",
                  "type": "string",
                  "description": "The city component of the address"
                },
                "addressRegion": {
                  "example": "QLD",
                  "type": "string",
                  "description": "The state component of the address"
                },
                "postalCode": {
                  "example": "4217",
                  "type": "string",
                  "description": "The postal code"
                },
                "addressCountry": {
                  "example": "AU",
                  "type": "string",
                  "description": "Country."
                }
              }
            }
          }
        },
        "invoicee": {
          "description": "Party to whom an invoice is issued.",
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "default": "Party",
              "enum": [
                "Party"
              ]
            },
            "id": {
              "example": "did:web:waveridersupplies.example.com",
              "type": "string",
              "format": "uri",
              "description": "A unique party identifier."
            },
            "name": {
              "example": "Wave Rider Supplies, Inc",
              "type": "string",
              "description": "Trade party name."
            },
            "postalAddress": {
              "description": "The postal address of the party.",
              "type": "object",
              "properties": {
                "type": {
                  "type": "string",
                  "default": "Address",
                  "enum": [
                    "Address"
                  ]
                },
                "streetAddress": {
                  "example": "210 Ocean Road",
                  "type": "string",
                  "description": "The street component of the address"
                },
                "addressLocality": {
                  "example": "Williamsburg",
                  "type": "string",
                  "description": "The city component of the address"
                },
                "addressRegion": {
                  "example": "NSW",
                  "type": "string",
                  "description": "The state component of the address"
                },
                "postalCode": {
                  "example": "75002",
                  "type": "string",
                  "description": "The postal code"
                },
                "addressCountry": {
                  "example": "AU",
                  "type": "string",
                  "description": "Country."
                }
              }
            }
          }
        },
        "deliveryLocation": {
          "description": "Location to which a consignment is to be delivered to the final consignee.",
          "type": "object",
          "required": [
            "name"
          ],
          "properties": {
            "name": {
              "example": "Wave Rider Supplies Warehouse",
              "type": "string",
              "description": "Name of the delivery location"
            },
            "streetAddress": {
              "example": "210 Ocean Road",
              "type": "string",
              "description": "The street component of the address"
            },
            "addressLocality": {
              "example": "Williamsburg",
              "type": "string",
              "description": "The city component of the address"
            },
            "addressRegion": {
              "example": "NSW",
              "type": "string",
              "description": "The state component of the address"
            },
            "postalCode": {
              "example": "75002",
              "type": "string",
              "description": "The postal code"
            },
            "addressCountry": {
              "example": "AU",
              "type": "string",
              "description": "Country"
            },
            "unLocode": {
              "type": "string",
              "format": "uri",
              "description": "UN/LOCODE location identifier"
            }
          }
        },
        "paymentTerms": {
          "example": "Net 30 days",
          "type": "string",
          "description": "Identification of the terms of payment between the parties to a transaction."
        },
        "paymentMethod": {
          "example": "Wire Transfer",
          "type": "string",
          "description": "Code specifying a method of payment."
        },
        "allowanceCharge": {
          "description": "Code specifying a type of an adjustment to a monetary amount such as an allowance or charge.",
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "allowance",
                "charge"
              ],
              "description": "Whether this is an allowance or charge"
            },
            "description": {
              "type": "string",
              "description": "Description of the allowance or charge"
            },
            "amount": {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string",
                  "default": "MonetaryAmount",
                  "enum": [
                    "MonetaryAmount"
                  ]
                },
                "amount": {
                  "type": "number",
                  "format": "float",
                  "description": "The monetary amount"
                },
                "currency": {
                  "type": "string",
                  "description": "Currency code"
                }
              }
            }
          }
        },
        "totalOrderAmount": {
          "description": "Total amount of an order.",
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "default": "MonetaryAmount",
              "enum": [
                "MonetaryAmount"
              ]
            },
            "amount": {
              "example": 73250,
              "type": "number",
              "format": "float",
              "description": "Total order amount"
            },
            "currency": {
              "example": "USD",
              "type": "string",
              "description": "Currency code"
            }
          }
        },
        "orderedItems": {
          "name": "Ordered Items",
          "description": "Items being ordered",
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "productIdentifier",
              "quantityOrdered"
            ],
            "properties": {
              "type": {
                "type": "string",
                "default": "TradeLineItem",
                "enum": [
                  "TradeLineItem"
                ]
              },
              "productIdentifier": {
                "example": "SURF-LB-001",
                "type": "string",
                "description": "Reference number identifying a product."
              },
              "product": {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "default": "Product",
                    "enum": [
                      "Product"
                    ]
                  },
                  "id": {
                    "example": "urn:uuid:surf-001-longboard",
                    "type": "string",
                    "format": "uri",
                    "description": "A unique identifier for the product."
                  },
                  "name": {
                    "example": "Professional Longboard - Ocean Series",
                    "type": "string",
                    "description": "Product name"
                  },
                  "description": {
                    "example": "High-performance longboard with premium bamboo core and fiberglass construction, 9'6\" length",
                    "type": "string",
                    "description": "Product description"
                  }
                },
                "description": "Product details"
              },
              "quantityOrdered": {
                "example": 25,
                "type": "number",
                "description": "The quantity which has been ordered."
              },
              "unitPrice": {
                "description": "Price per unit of quantity on which an article item amount is calculated.",
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "default": "MonetaryAmount",
                    "enum": [
                      "MonetaryAmount"
                    ]
                  },
                  "amount": {
                    "example": 750,
                    "type": "number",
                    "format": "float",
                    "description": "Unit price amount"
                  },
                  "currency": {
                    "example": "USD",
                    "type": "string",
                    "description": "Currency code"
                  }
                }
              },
              "lineTotal": {
                "description": "Total amount for this line item.",
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "default": "MonetaryAmount",
                    "enum": [
                      "MonetaryAmount"
                    ]
                  },
                  "amount": {
                    "example": 18750,
                    "type": "number",
                    "format": "float",
                    "description": "Line total amount"
                  },
                  "currency": {
                    "example": "USD",
                    "type": "string",
                    "description": "Currency code"
                  }
                }
              }
            },
            "description": "A line item in the purchase order specifying products or services to be purchased."
          }
        }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": true
}
