{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agent-mandate.ru/format/mandate-0.1.schema.json",
  "title": "Мандат агента 0.1 (черновик)",
  "description": "Открытый формат поручения человека ИИ-агенту на покупку или платёж. Черновик, не стандарт. CC BY 4.0, https://agent-mandate.ru/format/",
  "type": "object",
  "required": [
    "type",
    "version",
    "id",
    "principal",
    "agent",
    "purpose",
    "limit",
    "valid_from",
    "valid_until",
    "confirm",
    "created"
  ],
  "properties": {
    "type": {
      "const": "agentmandate.intent"
    },
    "version": {
      "const": "0.1"
    },
    "id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 64,
      "description": "Номер мандата, уникальный у доверителя, например AM-2026-000142"
    },
    "principal": {
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "contact": {
          "type": "string",
          "maxLength": 200
        }
      },
      "additionalProperties": false,
      "description": "Кто поручил (доверитель)"
    },
    "agent": {
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "id": {
          "type": "string",
          "format": "uri",
          "description": "Адрес карточки или паспорта агента"
        }
      },
      "additionalProperties": false,
      "description": "Кому поручено"
    },
    "purpose": {
      "type": "string",
      "minLength": 1,
      "maxLength": 500,
      "description": "Поручение обычными словами"
    },
    "limit": {
      "type": "object",
      "required": [
        "amount",
        "currency"
      ],
      "properties": {
        "amount": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "per_purchase": {
          "type": "number",
          "exclusiveMinimum": 0
        }
      },
      "additionalProperties": false
    },
    "valid_from": {
      "type": "string",
      "format": "date-time"
    },
    "valid_until": {
      "type": "string",
      "format": "date-time"
    },
    "merchants": {
      "type": "object",
      "properties": {
        "categories": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "domains": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "hostname"
          },
          "uniqueItems": true
        }
      },
      "additionalProperties": false,
      "description": "Где можно покупать. Нет поля — любые продавцы"
    },
    "confirm": {
      "enum": [
        "before_each_payment",
        "above_amount",
        "never"
      ]
    },
    "confirm_above": {
      "type": "number",
      "exclusiveMinimum": 0
    },
    "revocation": {
      "type": "string",
      "maxLength": 300
    },
    "created": {
      "type": "string",
      "format": "date-time"
    }
  },
  "patternProperties": {
    "^x-": {}
  },
  "additionalProperties": false,
  "if": {
    "properties": {
      "confirm": {
        "const": "above_amount"
      }
    }
  },
  "then": {
    "required": [
      "confirm_above"
    ]
  }
}
