{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agentictradestandard.org/schemas/terms-snapshot.schema.json",
  "title": "SACP terms snapshot",
  "description": "The exact terms a customer approves. Hash it with SHA-256 over RFC 8785 canonical JSON. Added in SACP 1.1.0-draft.",
  "type": "object",
  "required": [
    "sacp_terms_version",
    "quote_id",
    "merchant",
    "items",
    "currency",
    "subtotal",
    "taxes",
    "shipping",
    "total",
    "valid_from",
    "valid_until"
  ],
  "additionalProperties": false,
  "properties": {
    "sacp_terms_version": {
      "const": "1.1"
    },
    "quote_id": {
      "type": "string",
      "minLength": 1
    },
    "merchant": {
      "type": "object",
      "required": [
        "id",
        "name",
        "origin"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "origin": {
          "type": "string",
          "format": "uri"
        }
      }
    },
    "items": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "id",
          "name",
          "qty",
          "unit_price",
          "line_total",
          "availability"
        ],
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "qty": {
            "type": "integer",
            "minimum": 1
          },
          "unit_price": {
            "type": "string",
            "pattern": "^[0-9]+(\\.[0-9]{1,6})?$"
          },
          "line_total": {
            "type": "string",
            "pattern": "^[0-9]+(\\.[0-9]{1,6})?$"
          },
          "availability": {
            "enum": [
              "in_stock",
              "backorder",
              "made_to_order"
            ]
          },
          "available_from": {
            "type": "string",
            "format": "date"
          }
        }
      }
    },
    "currency": {
      "type": "string",
      "pattern": "^[A-Z]{3}$"
    },
    "subtotal": {
      "type": "string",
      "pattern": "^[0-9]+(\\.[0-9]{1,6})?$"
    },
    "taxes": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "type",
          "rate",
          "amount",
          "included"
        ],
        "additionalProperties": false,
        "properties": {
          "type": {
            "type": "string"
          },
          "rate": {
            "type": "string",
            "pattern": "^[0-9]+(\\.[0-9]{1,6})?$"
          },
          "amount": {
            "type": "string",
            "pattern": "^[0-9]+(\\.[0-9]{1,6})?$"
          },
          "included": {
            "type": "boolean"
          }
        }
      }
    },
    "shipping": {
      "type": "object",
      "required": [
        "method",
        "cost"
      ],
      "additionalProperties": false,
      "properties": {
        "method": {
          "type": "string"
        },
        "carrier": {
          "type": "string"
        },
        "cost": {
          "type": "string",
          "pattern": "^[0-9]+(\\.[0-9]{1,6})?$"
        },
        "eta_date": {
          "type": "string",
          "format": "date"
        },
        "destination": {
          "type": "object",
          "required": [
            "country"
          ],
          "additionalProperties": false,
          "properties": {
            "country": {
              "type": "string",
              "pattern": "^[A-Z]{2}$"
            },
            "postcode_area": {
              "type": "string"
            }
          }
        }
      }
    },
    "total": {
      "type": "string",
      "pattern": "^[0-9]+(\\.[0-9]{1,6})?$"
    },
    "valid_from": {
      "type": "string",
      "format": "date-time"
    },
    "valid_until": {
      "type": "string",
      "format": "date-time"
    },
    "tolerance": {
      "description": "Allowed change before the approval is void. Every field defaults to zero. Merchant, item, quantity and currency changes are never tolerated.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "price_increase_max_percent": {
          "type": "string",
          "pattern": "^[0-9]+(\\.[0-9]{1,6})?$",
          "default": "0"
        },
        "price_increase_max_amount": {
          "type": "string",
          "pattern": "^[0-9]+(\\.[0-9]{1,6})?$",
          "default": "0.00"
        },
        "shipping_cost_increase_max": {
          "type": "string",
          "pattern": "^[0-9]+(\\.[0-9]{1,6})?$",
          "default": "0.00"
        },
        "eta_delay_max_days": {
          "type": "integer",
          "minimum": 0,
          "default": 0
        },
        "total_increase_max": {
          "type": "string",
          "pattern": "^[0-9]+(\\.[0-9]{1,6})?$",
          "default": "0.00"
        }
      }
    }
  }
}
