{
  "type": "object",
  "additionalProperties": false,
  "required": [
    "version",
    "taskId",
    "authorizationRef",
    "policyRef",
    "criterionRef",
    "contract",
    "attempts",
    "acceptance",
    "invoice",
    "settlement"
  ],
  "properties": {
    "version": {
      "const": "0.1"
    },
    "taskId": {
      "type": "string",
      "pattern": "^[A-Za-z0-9._:-]{1,100}$"
    },
    "authorizationRef": {
      "type": "string",
      "pattern": "^[A-Za-z0-9._:-]{1,100}$"
    },
    "policyRef": {
      "type": "string",
      "pattern": "^[A-Za-z0-9._:-]{1,100}$"
    },
    "criterionRef": {
      "type": "string",
      "pattern": "^[A-Za-z0-9._:-]{1,100}$"
    },
    "contract": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "currency",
        "billingBasis",
        "unitPriceMinor",
        "retryCostBearer"
      ],
      "properties": {
        "currency": {
          "const": "USD"
        },
        "billingBasis": {
          "enum": [
            "attempt",
            "accepted_outcome"
          ]
        },
        "unitPriceMinor": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000000000
        },
        "retryCostBearer": {
          "enum": [
            "operator",
            "provider",
            "buyer",
            "unresolved"
          ]
        }
      }
    },
    "attempts": {
      "type": "array",
      "minItems": 1,
      "maxItems": 100,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "attemptId",
          "authorizationRef",
          "policyRef",
          "status",
          "buyerBillable",
          "upstreamCostMinor"
        ],
        "properties": {
          "attemptId": {
            "type": "string",
            "pattern": "^[A-Za-z0-9._:-]{1,100}$"
          },
          "authorizationRef": {
            "type": "string",
            "pattern": "^[A-Za-z0-9._:-]{1,100}$"
          },
          "policyRef": {
            "type": "string",
            "pattern": "^[A-Za-z0-9._:-]{1,100}$"
          },
          "status": {
            "enum": [
              "accepted",
              "rejected",
              "pending"
            ]
          },
          "buyerBillable": {
            "type": "boolean"
          },
          "upstreamCostMinor": {
            "type": "integer",
            "minimum": 0,
            "maximum": 1000000000000
          }
        }
      }
    },
    "acceptance": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "criterionRef",
        "attemptId",
        "evidenceRef"
      ],
      "properties": {
        "status": {
          "enum": [
            "accepted",
            "rejected",
            "pending"
          ]
        },
        "criterionRef": {
          "type": "string",
          "pattern": "^[A-Za-z0-9._:-]{1,100}$"
        },
        "attemptId": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,100}$"
            },
            {
              "type": "null"
            }
          ]
        },
        "evidenceRef": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,100}$"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "invoice": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "totalMinor"
      ],
      "properties": {
        "totalMinor": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000000000
        }
      }
    },
    "settlement": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "amountMinor",
        "reference"
      ],
      "properties": {
        "status": {
          "enum": [
            "pending",
            "settled",
            "disputed"
          ]
        },
        "amountMinor": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000000000
        },
        "reference": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,100}$"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    }
  },
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://decentralised.news/data/agent-outcome-receipts/v0.1/receipt.schema.json",
  "title": "DN Outcome Receipt Draft Profile v0.1",
  "$comment": "Structural schema only. Cross-record references, arithmetic and unresolved/disputed states are checked by checkOutcomeReceipt. Neither validates external evidence, signatures or actual payments."
}
